[Dbix-class] Many-to-many with attributes

Jonathan Tweed jonathan at tweed.name
Sun Nov 27 22:14:42 CET 2005


On 26 Nov 2005, at 21:23, Matt S Trout wrote:

> On Sat, Nov 26, 2005 at 12:06:19PM +0000, Jonathan Tweed wrote:
>> Hi List
>>
>> I'm trying to create a many-to-many mapping with attributes on the
>> join table. I've got the many-to-many bit working, but can't figure
>> out how to get at the attributes. My current attempt is as follows:
>>
>> <snip>
>
> The above changes means that you'll get a ListSubscriber object  
> back but
> $ls->email and ->id will be proxied through to the Subscriber  
> object (which
> will already have been grabbed by the prefetch). You can still call
> $ls->subscriber->email if required though.

Thanks Matt, that works really well. I can see no mention of either  
prefetch or proxy in the documentation so I'd never have figured it  
out on my own.

One question. Why does my original attempt not work? It seems more  
obvious to me, and indeed it is just an extension of the many-to-many  
example in the docs. The SQL that is generated is correct, but the  
columns are not being exposed in the result set, even when I  
specifically ask for them. As DBIx::Class is supposed to be result  
set rather than table oriented, why is this?

>> Thanks for any help, I'm an ex Class::DBI user but very new to
>> DBIx::Class and so far I'm impressed. When I get this working I'll
>> add an example to the wiki.
>
> That'd be much appreciated.

I'll get on it. I'll add to it when I figure out adding, updating and  
deleting.

Thanks
Jonathan



More information about the Dbix-class mailing list