[Solar-talk] Selecting Cols w/ eager

Raymond Kolbe rkolbe at gmail.com
Mon Nov 19 08:50:42 CST 2007


>
> Please, for the love of God if you have something like
>
> @param array $opts Additional options for the relationship.
>
> in the inline documentation please define what those opts are ;p


Ditto...but that will come with documentation (work in progress).

If I understand you correctly, you are saying that the cols should be
defined with the cols key in the model. I don't think this would be
efficient since I do not always want to return all cols from a related
model/table even if they are predefined.

Example:

*Vendor_Model_Example
*
$_hasMany('user', array(
  'foreign_class'  => 'Vendor_Model_Users',
  'native_col'  => 'user_id',
  'foreign_col'  => 'id',
));

*Vendor_Model_Users*

$_belongsTo('Vendor_Model_Example', array(
  'foreign_class'  => 'Vendor_Model_Example',
  'native_col'  => 'id',
  'foreign_col'  => 'user_id',
  'cols'  => array('user.id', 'user.name', 'user.email', 'user.birthday',
etc. etc.)
));

Is this what you were referring to? If this is the case, when I call
Vendor_Model_Example using eager to include Vendor_Model_Users, it should
return data from the cols user.id', 'user.name', 'user.email', '
user.birthday'

Now what if I ONLY wanted the user.id or just the id and name? Wouldn't
calling all of the cols be a waste of resources?

I bring this up because I have a user model that one of my other models
(Vendor_Model_Example) relates to. When I grab the related cols, it returns
the md5 hash password as well as the salt, etc. etc. I don't like the idea
of passing this information around freely and also don't like the fact that
if the col was called it is set to NULL, which later allows you to set the
data and save it back to the database (using save()).

Any suggestions appreciated.

Thank you,
Raymond K.

On Nov 19, 2007 3:57 AM, Ian Szewczyk <roamzero at gmail.com> wrote:

> You can define the cols that are loaded from a relationship by using
> the 'cols' opt (array of cols or a string) when setting up the
> hasOne(), hasMany(), etc relationships (Meaning that sometimes you
> need to 'redo' some relations for customization purposes I guess,
> unless Im wrong and someone wants to clarify?).  If I'm right though
> maybe it would be practical to have an eager_opts array that can be
> merged into the relationship opts of whatever 'base' relationship you
> have setup and choose to use?
>
> Note to Paul:
>
> Please, for the love of God if you have something like
>
> @param array $opts Additional options for the relationship.
>
> in the inline documentation please define what those opts are ;p
>
>
>
> On Nov 18, 2007 10:30 PM, Raymond Kolbe <rkolbe at gmail.com> wrote:
> > Hey folks,
> > I couldn't find a way to do this so I thought I would ask ;-)
> >
> > Let's say I have a controller, Vendor_App_ExampleController. This
> controller
> > uses the model called Vendor_Model_Example and this model has a
> relationship
> > to Vendor_Model_Users.
> >
> > In the controller I only call Vendor_Model_Example and pass it (or
> rather,
> > pass it to fetchAll()) 'eager' => 'user' (the relationship name I setup
> in
> > the Example model) and return it in a variable named, let's say
> > $_example_model. Now I can access $this->_example_model->name and
> > $this->_example_model->user->name (given that I have cols named 'name'
> in
> > the database table).
> >
> > The problem I am having is this...how can I specify the cols for eager?
> > Here's some quick & dirty code:
> >
> > (in Vendor_App_ExampleController)
> >
> > $params = array(
> >   'eager' => 'user',
> >   'cols'   => array('users.id', 'users.name'),
> > );
> >
> > As you can see, the query tries to search for these columns on the table
> for
> > Example and not Users. I have tried a few different things but cannot
> seem
> > to find a way to work around this. I would rather not have Solar return
> all
> > cols from related tables that I call using eager ( e.g. password, salt,
> > etc).
> >
> > Thanks in advanced,
> > Raymond K.
> >
> > ps I am really liking the model relations in Solar. Keep up the good
> work!
> >
> > _______________________________________________
> > Solar-talk mailing list
> > Solar-talk at lists.solarphp.com
> > http://mailman-mail3.webfaction.com/listinfo/solar-talk
> >
> >
>
>
>
> --
> IAN SZEWCZYK
> roamzero at gmail.com
> _______________________________________________
> Solar-talk mailing list
> Solar-talk at lists.solarphp.com
> http://mailman-mail3.webfaction.com/listinfo/solar-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman-mail3.webfaction.com/pipermail/solar-talk/attachments/20071119/5d6ebd66/attachment-0001.html


More information about the Solar-talk mailing list