[Dbix-class] RecursiveUpdate and many to many

Zbigniew Lukasiak zzbbyy at gmail.com
Sun Sep 28 19:18:42 BST 2008


On Sun, Sep 28, 2008 at 6:56 PM, Oliver Gorwits
<oliver.gorwits at oucs.ox.ac.uk> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Zbigniew Lukasiak wrote:
>> I would like to include your critisizm of the support for many to
>> many in RecursiveUpdate in it's documentation.  Tell me if I get
>> it right. What I remember is two points:
>>
>> 1. That I rely on the fact that
>>
>> if($object->can($name) and
>> !$object->result_source->has_relationship($name) and
>> $object->can( 'set_' . $name ) )
>>
>> then $name must be a many to many pseudo relation.
>
> So my version of the heuristic goes like this:
>
> # start with a has_many relation.
> # check for related source having two belongs_to rels *only*,
> # and one of them refers to ourselves,
> # and at most one other col (id pk)
> # then the *other* rel on the related source is the "target"
>
> ...if that doesn't match, then the link table probably isn't sane,
> and the m2m code should be avoided.
>
> I have some code to do this, and am pondering its fragility before
> shipping in the next release of LFB's Metadata.pm.

I have a version of that as well - but in a different place :)  I use
it to add the m2m declarations to the Schema generated by the Loader -
ideally this could be added to the Loader code.  It might make sense
to add this here as a check as well - thanks for the idea.

>
> Ideally, DBIC would instead populate the relationship_info details
> after someone has set up __PACKAGE__->many_to_many(...). That would
> avoid this guesswork.

I have been nagging Matt about that for about 3 years (just after the
first release of InstantCRUD), there was a slight chance that this
would be added in 0.8 - but unfortunately it was somehow missed.  So
now we need to wait for the 0.9 release

-- 
Zbigniew Lukasiak
http://brudnopis.blogspot.com/
http://perlalchemy.blogspot.com/



More information about the DBIx-Class mailing list