Count field in list_items
Hey,
is it possible to have a column in the list view of a simple module where I can display the count of a has_many table?
For example I have a model where I display vehicles. In a has_many relationship I have n images for a vehicle. Now in list_items I want to have one column which displays the count value of the has_many relationship...
How can I achieve this?
Comments
public function list_items($limit = NULL, $offset = NULL, $col = 'nav_key', $order = 'desc', $just_count = FALSE) { = mytable.id AND fuel_pages_relationships.candidate_table="my_images" ', "left"); $this->db->select('my_table.id, mycolumn1, mycolumn2, SELECT(COUNT(*) FROM fuel_relationships where candidate_table ="mytable" AND candidate_key = mytable.id) as n', FALSE); return $data; }
That table also has a foreign_table and foreign_key which, depending on how it's saved may replace the candidate_table and candidate_key.