[Dbix-class] Resultset relation accessors
Matt S Trout
dbix-class at trout.me.uk
Mon Jun 8 19:14:02 GMT 2009
On Tue, May 26, 2009 at 01:49:05PM -0700, David Ihnen wrote:
> Sometimes I think i'm missing something obvious.
>
> In my application, for instance, a holiday can be assigned to a group.
>
> A group has many donors
> A donor might have many scheduled days
> A scheduled day is associated with a particular schedule
>
> In this spot in my application, the operation is "update group schedule" .
>
> I need to say "refresh all of the randomized scheduling for all of the
> schedules related to all of the donors in the group this schedule is
> on." To do that I need a list of those schedules.
>
> I first wrote that, for an update overload in my holiday class, like
> this. ($old is a hash ref to a copy of the get_columns from before the
> update took place)
>
> $self->groups->donors->schedule->ivr_schedule->search(
> { 'date_start' => { '<=' => $old->{holiday} }
> , -or =>
> [ 'date_end' => { '>=' => $old->{holiday} }
> , 'date_end' => undef
> ]
> } );
>
> But I got an error, something like "No such method 'donors' on class
> DBIx::Class::ResultSet"
>
> So I rewrote it...
>
> $self->groups->search_related('donors')->search_related('schedule')->search_related('ivr_schedule'
> , ...yaddayadda...
>
> and that worked.
>
> So it leaves me wondering if I missed something fundamental here. I
> have an object which is a result set of a particular record type. If I
> want the records that are related to that result set - why would I have
> to call 'related_resultset' - isn't "give me the related resulset" the
> only thing I could mean when I call ->relationship on a result set? If
> that is so, why aren't there accessors created on the resultset for the
> valid relations, to cut down on excessive verbosity that doesn't clarify?
I believe somebody tried that once.
Then they defined a relationship called 'next'.
Then they realised work would be involved and lost interest.
I don't see why it -can't- be done, just nobody's really tried. I reckon
you could do it as a schema component that wraps load_namespaces as a
start ...
--
Matt S Trout Catalyst and DBIx::Class consultancy with a clue
Technical Director and a commit bit: http://shadowcat.co.uk/catalyst/
Shadowcat Systems Limited
mst (@) shadowcat.co.uk http://shadowcat.co.uk/blog/matt-s-trout/
More information about the DBIx-Class
mailing list