[Solar-talk] Solar_Sql_Model Feedback
Ian Szewczyk
roamzero at gmail.com
Wed Jul 11 17:38:07 CDT 2007
On 7/11/07, Paul M Jones <pmjones at ciaweb.net> wrote:
> Hi Ian,
>
> > I've been messing around with the model system included in Solar and
> > it works pretty well, especially letting the relations setup joins
> > automatically. One issue however that I couldn't get around too easily
> > is when dealing large collections (it isn't even that big, 50 records)
> > that include eager loaded records. The data is already there, but when
> > getting around to iterating it generates many record objects, and this
> > slows things down pretty significantly, especially if you have more
> > relations.
>
> I don't have satisfactory answers for you on this yet, other than to
> say "I know it's not very good right now and I'll be working on it
> some more". The basic problem is that Solar_Sql_Model is still in
> its early stages, and eager-loading (among other things) is not very
> smart yet, as you have noticed.
>
>
> > Is there a way to just iterate through the data, and
> > optionally load the row objects if they are needed?
>
> In theory, if you don't specify eager-loading, it should only attempt
> to load the related record from the database when you ask for the
> corresponding property. That is, if you defined a related 'foo', it
> should stay NULL until you ask for $record->foo, at which time the
> __get() magic method hits the database and populates 'foo'. (Hope
> that makes sense).
>
>
> > Generating that
> > many objects when in most cases you just want to spit out the data
> > (which can be loaded ahead of time by specifying the eager stuff)
> > seems like overkill to me... I mean, I could just add a "data()"
> > method that returns _data, but then that would mean I'd have to access
> > the related records by double underscore which seems pretty
> > counter-intuitive.
>
> Also in theory, you should be able to get to the related records just
> by accessing the property normally; that is, you shouldn't have to
> call the __get() or __getFoo() method, just the $foo property.
>
>
> > Also, maybe you could consider loading the select objects through
> > dependencies possibly? In case I'm using a custom Solar_Sql_Select?
>
> That's a good idea -- can you enter it as a feature request for me so
> I don't forget?
>
> <http://solarphp.com/trac/newticket>
>
> Thanks for the feedback, please let me know if this was helpful or not.
>
>
> --
>
> 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>
>
>
> _______________________________________________
> Solar-talk mailing list
> Solar-talk at lists.solarphp.com
> http://mailman-mail3.webfaction.com/listinfo/solar-talk
>
Most of the things you mentioned I already understand. I guess I wasnt
clear in that I was hoping for away to iterate through the collection
of data, which may or may not include eager loaded relations, and
bypass the relatively expensive row-object creation that happens in
the offsetGet method, while at the same time keeping the way you
access the data more or less the same, and only "stepping into" the
row-object creation if you need to(wishful thinking maybe).
I imagine in most cases when you setup a collection object to pull out
data you would go the most practical route and eager load what you
need. Like on a blog page, you would get the comments eager loaded
with the users, and you could just want the data and not always the
fancy stuff that the respective row-objects provide, except maybe in
special cases. Something like this maybe:
foreach($commentCollection->asArray() AS $commentEntry) {
// No row objects made, only working with $_data array
echo $commentEntry->message;
echo $commentEntry->user->username;
// Special case
if ($something) {
$user = $commentEntry->user->asObject();
$user->someMethod();
}
}
--
IAN SZEWCZYK
roamzero at gmail.com
More information about the Solar-talk
mailing list