|XP is just a number|
The (Too-)Well Hidden Magic of "DBIx::Class"by sundialsvc4 (Abbot)
|on Feb 04, 2009 at 15:07 UTC||Need Help??|
sundialsvc4 has asked for the
wisdom of the Perl Monks concerning the following question:
I guess I just don't get the correct way to use “DBIx::Class.” The documentation is simply sketchy... I need some help to wrap my mind around this (no-doubt, wonderful...) thing.
What I have to deal with is fairly basic: retrieving related records, all 1:1, from a moderately-sized “fan” of related tables. A couple of these need to be inner-joins since the related records may or may not exist. I've auto-built a schema and it appears to have correctly captured the database relationships. So far, so good. I guess that I'm seeing “two ways to do it,” and I don't know which one is preferable.
One strategy, which I managed to perfect yesterday (and the behavior I was seeing may have been a bug in the package), is to use join= and prefetch= clauses in a search() call. I'm not quite sure if it is issuing INNER JOINs or not ... and I haven't quite figured out yet how to tell. But it does retrieve data from all the related tables (when records exist in all of them).
The second approach is find_related(), and I have yet to find a good, complex, example of this. It's one thing to simply build a long “train” of “related”s, but how do I extend things (using that approach) to build branches? How do I extend the graph at any point other than its (one...!) “leaf?”
And finally... what price am I paying? Is it efficient or not? How can I easily watch what it is generating?
All these questions. Such basic (I know...) questions...