[Solar-talk] Selecting Cols w/ eager

Paul M Jones pmjones at ciaweb.net
Mon Nov 19 12:12:58 CST 2007


On Nov 19, 2007, at 12:01 PM, Raymond Kolbe wrote:

>> IIRC you use the relationship name as the table name; e.g., on a
>> related "foo", use " foo.colname".  So in the above example you would
>> ask for 'cols' => array('user.id', 'user.name'), and not
>> "users.colname".
>
> users is my table name (sorry for the confusion)...so users.id  
> would be the col in that table.

Correct, but (iirc) the SQL gets constructed using the relationship  
name as the alias for the table.

If you turn on SQL profiling ($sql->setProfiling(true)), run the  
models, and then get the profile ($sql->getProfile()) you should see  
that the FROM and/or JOIN are on "users AS user".  So the fully- 
qualified name ought to be "user" in that case.

Hope that made sense, and that I recalled correctly.  ;-)


>> Alternatively, you can set up a "has-one limited_user" and define the
>> limited_user relation cols to be only the cols you want.  That can be
>> in addition to the regular "user" when you want all the cols.
>
> I think this would be the best option right now. However, I think I  
> would like to see a way to call the cols on the fly for all related  
> models/tables involved.

Yeah, I can see now that this would be quite useful.  Will involve  
some rewriting of how queries for the related tables are generated,  
but not a big deal given the usefulness of it.

Can you do me a favor?  Enter this as a feature request at <http:// 
solarphp.com/trac> so I don't forget.

Thanks!



--

Paul M. Jones  <http://paul-m-jones.com>

Solar: Simple Object Library and Application Repository
for PHP5.  <http://solarphp.com>

Join the Solar community wiki!  <http://solarphp.org>

Savant: The simple, elegant, and powerful solution for
templates in PHP.  <http://phpsavant.com>




More information about the Solar-talk mailing list