[eluser]TheJim[/eluser]
Oh, I missed that you had a question there.
[quote author="sheldonnbbaker" date="1270613632"]
EDIT: Assuming I use your example to get my widgets:
Code:
$versions = new Widget_version();
$versions->include_related('widget')->get();
foreach ($versions as ...
What would be a good way to get the ratings (and eventually comments, descriptions, etc.) for that widget_version (they would be has_many relationships)?[/quote]
You'd be stuck with running a get on each, since there's not really any way to combine them, and they'd all be has_many.
Well, I guess there's also the option of grabbing, say, all comments in one query and then relating them via PHP logic (easier if you have an in-table foreign key rather than a separate join table). That would be a trade-off of more memory usage for fewer queries. I would probably only go that route if pages are really sluggish though.
With a ton of relationships like that, at some point I'd probably start to ask myself if I need to store it this way. That is, is the rating really part of the comment? Or can more information be added to the Widget_version itself? Do I only care about the aggregate rating (storing a 0-5 as a field of Widget_version, or grabbing the SUM() from the DB rather than each record). That sort of thing.
Of course, not knowing anything about what you're trying to do, I have to give you the benefit of the doubt, and it may just be that you'll have to live with it and optimize in other ways (selecting only necessary fields, using get_iterated, creating good indexes in your DB, etc.). As long as you're not generating mammoth pages though (dozens of widgets with all their associated records, and all the queries that would entail), I think you'll have reasonable performance.