[eluser]macron[/eluser]
Hi
I have a problem figuring out how to use the select and select_func with a relation
I have two tables like this:
news: id, date and user_id
news_text: id, headline, content, language and news_model_id
Code:
class News_model extends DataMapper
{
var $table = 'news';
var $has_many = array('image_model', 'news_text_model');
var $created_field = 'date';
}
class News_text_model Extends DataMapper{
var $table = 'news_text';
var $has_one = array('news_model');
}
In my controller I do this:
Code:
$news = new News_model();
//$news->select('id, user_id)->select_func("DATE_FORMAT", array('@date', '[,]', "'%e %M %Y'"), 'date') <-- this is not working!!!
$news->order_by('date', 'DESC');
$news->get_paged(1, 3);
foreach($news as $item){
$item->news_text_model->where('language', lang('db_column'))->get();
}
$data['news'] = $news;
This all works fine, but the date field from news is in ISO format so I added
Code:
$news->select('id, user_id)->select_func("DATE_FORMAT", array('@date', '[,]', "'%e %M %Y'"), 'date');
but this does not work like I expected. The news_model object is now ok, date formatted etc., but the related objects cant be fetched anymore - they are null if I try to echo them.
Why is that?
/Kaj