[Dbix-class] Re: Testing for a join

Bill Moseley moseley at hank.org
Fri Dec 17 21:48:45 GMT 2010


On Fri, Dec 17, 2010 at 11:39 AM, Hernan Lopes <hernanlopes at gmail.com>wrote:

> i think this ?
> http://search.cpan.org/~frew/DBIx-Class-0.08124/lib/DBIx/Class/ResultSour=
ce.pm#relationships


That lists the relationships on a source.  And I'm looking for join info on
a resultset.

I resorted to matching either $rs->result_class or using Data::Visitor on
$rs->{attrs}{join} and looking for the join.  Doesn't seem that sound of a
solution, but appears to be working ok in my initial tests.




>
>
> On Fri, Dec 17, 2010 at 5:23 PM, Bill Moseley <moseley at hank.org> wrote:
>
>> To be a bit more succinct:
>>
>> Is there a method to see if a given $rs will join to (or query from) tab=
le
>> "foo" and if so what alias is used?
>>
>> I guess I could use $rs->as_query and a regular expression but wondered =
if
>> there might be a way that doesn't need to build the entire query.
>>
>>
>>
>> On Thu, Dec 16, 2010 at 4:59 PM, Bill Moseley <moseley at hank.org> wrote:
>>
>>>
>>> Music Database:  label -> cd -> track -> movement -> note
>>>
>>> So, there's a hierarchy of objects.
>>>
>>> Say, label has a "deleted" flag that always needs to be checked.  So, o=
ne
>>> option is to join and then add the check constraint in the base class:
>>>
>>> $rs =3D $schema->resultset( 'Track' )->join_label->check_deleted;
>>> $rs =3D $schema->resultset( 'Cd' )->join_label->check_deleted;
>>> $rs =3D $schema->resultset( 'Note' )->join_label->check_deleted;
>>>
>>>
>>> Where join_label() is a method in the specific resultset class -- e.g.
>>> ResultSet::CD has method join_label { return shift->search( undef, { jo=
in =3D>
>>> 'label' } ) }, and likewise, ResultSet::Note has a join_label method th=
at
>>> joins from note all the way to label.
>>>
>>> And then in the base ResultSet class check_deleted adds this to the
>>> resultset: sub check_deleted { return shift->search( { 'label.deleted' =
=3D> 0
>>> } ); }
>>>
>>> That works because every object is joined to the label object.
>>>
>>>
>>> Now, assume there's also a "deleted" flag on the track object.  If
>>> fetching a CD or Label then don't want to add a track.deleted =3D> 0
>>> condition, but if fetching track, movement, or a note I do want to add =
that
>>> condition.
>>>
>>> Is it possible to "know" in the base "check_deleted' method that the $rs
>>> is fetching either a track (or is joined to track) and then conditional=
ly
>>> add the track.deleted check?
>>>
>>>
>>> --
>>> Bill Moseley
>>> moseley at hank.org
>>>
>>
>>
>>
>> --
>> Bill Moseley
>> moseley at hank.org
>>
>> _______________________________________________
>> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
>> IRC: irc.perl.org#dbix-class
>> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
>> Searchable Archive:
>> http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>>
>
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive:
> http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>



-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20101217/326=
9589f/attachment.htm


More information about the DBIx-Class mailing list