[Dbix-class] RecursiveUpdate and many to many
Oliver Gorwits
oliver.gorwits at oucs.ox.ac.uk
Sun Sep 28 17:56:11 BST 2008
-----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.
Ideally, DBIC would instead populate the relationship_info details
after someone has set up __PACKAGE__->many_to_many(...). That would
avoid this guesswork.
regards,
oliver.
- --
Oliver Gorwits, Network and Telecommunications Group,
Oxford University Computing Services
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFI37cr2NPq7pwWBt4RAi7QAKCMuB48A6MfPEA5bZhflJ7avQLYiwCg9GbX
L+cFSGE/tLZ/cI6YgK860UM=
=JN85
-----END PGP SIGNATURE-----
More information about the DBIx-Class
mailing list