Development

ApplyingCustomJoinsInDoSelect (diff)

You must first sign up to be able to contribute.

Changes between Version 3 and Version 4 of ApplyingCustomJoinsInDoSelect

Show
Ignore:
Author:
anonymous (IP: 219.77.4.200)
Timestamp:
06/12/06 16:00:14 (11 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ApplyingCustomJoinsInDoSelect

    v3 v4  
    11== Applying custom joins in doSelect* method == 
    22 
    3 You want to join a table when running doSelect method to save you from doing multiple queries. If for various reasons you cannot refer it to a foreign key column, you can still write your own {{{doSelectJoin*}}} method like the code generated by Propel. This page describes how to achieve this
     3You want to join a table when running doSelect method to save you from doing multiple queries, but for various reasons you cannot refer it to a foreign key column in the schema, so propel doesn't generate the code for you. This page describes how to still write your own {{{doSelectJoin*}}} method like the code generated by Propel
    44 
    55Say you want to join {{{Article}}} with {{{Book}}} then join with {{{Category}}}, with {{{article.book_id = book.id AND book.category_id = category.id}}}. 
    134134That's it! You can use {{{ArticlePeer::doSelectJoinBookAndCategory()}}} to fetch the books also with the book and category fields. Calling {{{$article->getBook()}}} and {{{$article->getCategory()}}} won't cause an extra query. To use this function in a pager, call {{{$pager->setPeerMethod('doSelectJoinBookAndCategory');}}}. Note that you can use the ordinal doCount for the above example. However if you are doing something that affects the result count (like grouping, or joinging that causes some rows not fetched) in the {{{doSelect*}}} method, you will have to roll your own {{{doCount*}}} method and call {{{$pager->setPeerMethod('doCountJoinBookAndCategory');}}} to ensure proper count.  
    135135 
    136