It looks like you're new here. If you want to get involved, click one of these buttons!
public $belongs_to = array('missions' => 'missions_model');
public function get_missions() {
$miss = $this->lazy_load(array('id' => $this->mission_id), "missions_model", true, array('order_by' => 'datum_beginn desc, uhrzeit_beginn desc', 'limit' => 10));
return $miss;
}
Comments
public function get_missions() { $miss = $this->lazy_load(array('id' => $this->mission_id), "missions_model", true, array('order_by' => 'datum_beginn desc, uhrzeit_beginn desc', 'limit' => 5)); $this->debug_query(); return $miss; }
In the view I have
<? $a = $data->get_missions(); die(); ?>
The SQL produced is:
SELECT `fw_fahrzeuge`.* FROM (`fw_fahrzeuge`) WHERE `fw_fahrzeuge`.`id` = '3' AND `fw_fahrzeuge`.`published` = 'yes' LIMIT 1
That is very strange because I lazy load the fw_missions table via the missions_model...
CI()->missions_model->debug_query();
One thing to note that if you have a has_many relationship like say a "tags" has_many relationship on an articles model, you can do the following to return the model instance back with the "where_in" active record already assigned to it to do further active query manipulation:
$tags_model = $article->get_tags(TRUE); $tags = $tags->find_all(array('context' => 'article'), 'name asc');
In the frontend I want to show only the last 5 missions of the vehicle.
Because of this I want to lazyload the relationship.
At the moment I overloaded the get_missions with a new sql to achieve this.
$missions = $rec->get_missions(TRUE)->find_all(array(), 5);
The TRUE, returns the model with the wherein already applied instead of the IDs which allows for further active record querying (or limiting in your case)