[Dbix-class] Best practice for multi-related table

Matt S Trout dbix-class at trout.me.uk
Thu May 29 11:13:24 BST 2008


On Mon, May 12, 2008 at 01:41:07AM -0300, Silvio Almeida wrote:
> Hi, I'm new to the list and ask you for design advice. I'm working on a 
> Catalyst project, trying to preserve old code if possible, so this is my 
> idea:
> 
> What I call "multi-related table" is something like having a table Href 
> that could be addressed by different tables:
> 
> Text->has_many(links, Href);
> Bookmark->has_many(links, Href);
> Author->has_one(homepage, Href);
> 
> I tried different geometries but it seem to be impossible to succesfully 
> create all the inverse relashionships simultaneously:
> 
> Href->belongs_to(Text);
> Href->belongs_to(Bookmark);
> Href->belongs_to(Author);
> 
> Maybe I'm looking for something like might_belong_to, which doesn't 
> exists, maybe it's just bad design. As a matter of fact, Href knows 
> nothing about which objects its foreign keys come from, so probably 
> those inverse relationships are be pointless anyway. Is it ok to go on 
> without'em?

No, you just want a might_have. But it doesn't matter if you leave 'em out.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list