Re: Multiple Model Pagination
Containable could create multiple queries. This is the solution I went for: http://github.com/ionas/sna/blob/master/www/app/controllers/profiles_controller.php#L112 This could be another solution (not tested yet): http://mark-story.com/posts/view/using-bindmodel-to-get-to-deep-relations (internally pagination uses find() as well) Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Multiple Model Pagination
Here's a new tutorial that's a bit more relevant http://foldifoldi.com/news/?p=466 On Dec 25, 9:15 am, foldiman wrote: > Andrew, > It sounds like you want to use a join in yourpaginationquery. If you > have set up your model relationships, the joins may happen > automagically. However, you can force the join using the 'joins' > parameter in thepaginationquery. For example: > > $joins1 = array( > 'table' => 'bug_relations', > 'alias' => 'BugRel', > 'type' => 'inner', > 'foreignKey' => false, > 'conditions' => array( > 'BugsGarden.bug_relation_id = BugRel.id', > 'BugRel.name LIKE' => '%' . 'beetle' . '%' > ) > > $this->paginate= array( > 'BugsGarden' => array( > 'limit' => 20, > 'order' => array('BugsGarden.created' => 'asc'), > 'contain' => array( > 'Garden', 'BugRelation' > ), > 'joins' => array($joins1) > ) > ) > > If you wanted to see what Bugs were found in which > Garden...specifically which bugs have the string 'beetle' in their > name, you could paginate a relation table that carries which bugs are > in which garden using ids as foreign keys. You can then get the name > from another tablein this example a table called 'bug_relations' > that carries info about the various bugs. The join to get the full > names or other info is forced in the 'joins' param of thepagination > query. Remember to include the table name in your sort keys. > > An example of cross database queries is also here. > > http://foldifoldi.com/news/?p=436 > > I hope this helps, > Vince > > On Dec 24, 12:32 pm, Andrew wrote: > > > > > Greetings, all, > > I know other people have worked on this before, but I haven't > > been able to find a solution so far. So, the long and short of it is > > that I've got multiple models that I want to mix into one view sorted > > by the date created. > > > I've got a 'created' datetime field in the database already. I > > understand how to paginate each of the individual database calls and > > merging that info together, but that doesn't work with the core > >paginationstuff as I understand it. Do you have any suggestions for > > developing this? > > > Also, I'd like to keep the number of database calls down, so any > > suggestions along those lines would be great. Thanks! > > > ~Andrew Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Multiple Model Pagination
Andrew, It sounds like you want to use a join in your pagination query. If you have set up your model relationships, the joins may happen automagically. However, you can force the join using the 'joins' parameter in the pagination query. For example: $joins1 = array( 'table' => 'bug_relations', 'alias' => 'BugRel', 'type' => 'inner', 'foreignKey' => false, 'conditions' => array( 'BugsGarden.bug_relation_id = BugRel.id', 'BugRel.name LIKE' => '%' . 'beetle' . '%' ) $this->paginate= array( 'BugsGarden' => array( 'limit' => 20, 'order' => array('BugsGarden.created' => 'asc'), 'contain' => array( 'Garden', 'BugRelation' ), 'joins' => array($joins1) ) ) If you wanted to see what Bugs were found in which Garden...specifically which bugs have the string 'beetle' in their name, you could paginate a relation table that carries which bugs are in which garden using ids as foreign keys. You can then get the name from another tablein this example a table called 'bug_relations' that carries info about the various bugs. The join to get the full names or other info is forced in the 'joins' param of the pagination query. Remember to include the table name in your sort keys. An example of cross database queries is also here. http://foldifoldi.com/news/?p=436 I hope this helps, Vince On Dec 24, 12:32 pm, Andrew wrote: > Greetings, all, > I know other people have worked on this before, but I haven't > been able to find a solution so far. So, the long and short of it is > that I've got multiple models that I want to mix into one view sorted > by the date created. > > I've got a 'created' datetime field in the database already. I > understand how to paginate each of the individual database calls and > merging that info together, but that doesn't work with the core > pagination stuff as I understand it. Do you have any suggestions for > developing this? > > Also, I'd like to keep the number of database calls down, so any > suggestions along those lines would be great. Thanks! > > ~Andrew Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Multiple Model Pagination
I would create an SQL statement using UNION to combine all the data from multiple models and ordered by the same ORDER BY. But this means probably that you have to use a custom query and I don't know if that can be paginated! Example: (SELECT a.id AS Result.id, a.name AS Result.name, a.created AS Result.created FROM table_a AS a WHERE xxx = yyy) UNION (SELECT b.id AS Result.id, b.name AS Result.name, b.created AS Result.created FROM table_b AS b WHERE xxx = yyy) UNION (SELECT c.id AS Result.id, c.name AS Result.name, c.created AS Result.created FROM table_c AS c WHERE xxx = yyy) ORDER BY Result.created I hope you get the idea :) Enjoy, John On Dec 24, 7:32 pm, Andrew wrote: > Greetings, all, > I know other people have worked on this before, but I haven't > been able to find a solution so far. So, the long and short of it is > that I've got multiple models that I want to mix into one view sorted > by the date created. > > I've got a 'created' datetime field in the database already. I > understand how to paginate each of the individual database calls and > merging that info together, but that doesn't work with the core > pagination stuff as I understand it. Do you have any suggestions for > developing this? > > Also, I'd like to keep the number of database calls down, so any > suggestions along those lines would be great. Thanks! > > ~Andrew Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Multiple Model Pagination
Greetings, all, I know other people have worked on this before, but I haven't been able to find a solution so far. So, the long and short of it is that I've got multiple models that I want to mix into one view sorted by the date created. I've got a 'created' datetime field in the database already. I understand how to paginate each of the individual database calls and merging that info together, but that doesn't work with the core pagination stuff as I understand it. Do you have any suggestions for developing this? Also, I'd like to keep the number of database calls down, so any suggestions along those lines would be great. Thanks! ~Andrew Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en