[Dbix-class] RecursiveUpdate and many to many

Pedro Melo melo at simplicidade.org
Mon Sep 29 17:39:25 BST 2008


Hi,

On Sep 29, 2008, at 4:50 PM, Matt S Trout wrote:

> On Sun, Sep 28, 2008 at 05:56:11PM +0100, Oliver Gorwits wrote:
>> Ideally, DBIC would instead populate the relationship_info details
>> after someone has set up __PACKAGE__->many_to_many(...). That would
>> avoid this guesswork.
>
> That would make no sense at all since many-to-many is NOT A  
> RELATIONSHIP.

I've been in this list for some years now that I've seen this phrase  
written several times.

<pedantic>
If I recall correctly my time at CS department where I was forced to  
read the relational model (not the -for-dummies version that is SQL  
today. but the true horrid version), many-to-many was in fact a  
relationship.

The classical link-table that we came to love/hate is in fact an  
"implementation decision" in the sense that current SQL servers don't  
have native support for many-to-many (in fact the SQL language is the  
one who does not support it), so we hacked around it.

It was expected that implementations of the relation model would allow  
you do declare such relationship and it would just work. I'm assuming  
that the pragmatic engineers of those implementation would in fact  
create a link table, only one hidden to you.

In practice, I don't believe anybody did in the end.
</pedantic>

Having said that, it is trivial to use your own base class for your  
sources in a way that you can catch many-to-many declarations and  
cache the result somewhere private (your own version of  
relationship_info()).

I say that this is possible because I have code running in production  
that does exactly that: creates a parallel relationship_info(), and  
implements a similar recursive update/create/delete data-driven  
operation, including many-to-many relationships.

The current, tested (in the sense that it has tests) and documented  
version is not available. I don't have permission (yet) to release it.

Best regards,
-- 
Pedro Melo
Blog: http://www.simplicidade.org/notes/
XMPP ID: melo at simplicidade.org
Use XMPP!





More information about the DBIx-Class mailing list