Re: [CDBI] Many-to-Many - why no CDBI::Relationship?
Matt S Trout <dbix-class-uY5y5/[email protected]>
| Newsgroups | gmane.comp.lang.perl.modules.class-dbi |
|---|---|
| Message-ID | <[email protected]> |
Ryan Tate wrote:
> Is there a reason no one has ever written a Class::DBI::Relationship
> subclass for many-to-many?
>
> The idea, of course, would be to get all objects related via a mapping
> table with a single database query (using a SQL join), including all
> Essential attributes. Right now, the has_many many-to-many hack only
> gets you the id of each related object, and you need to do a separate
> db query for each object if you want to flesh out the other
> attributes.
>
> Are most people happing writing custom SQL as needed? Or constructing
> the appropriate search query in Class::DBI::Sweet? As far as I can
> tell, Sweet can get many-to-many related objects with one query, but
> you have to construct the correct ->search.
I did this a couple of times myself, but was never able to get code I was
happy with since CDBI doesn't -really- understand joins, even after the work I
did in Sweet to be able to support the queries involved.
In DBIx::Class we found that a many-many isn't really a relationship in its
own right, it's a bridge over two existing relationships. You could maybe
backport it but Class::DBI (as the description "Simple Database Abstraction")
suggests doesn't really understand databases well enough to do it properly;
you'll run into all sorts of nasty corner cases and places where you have to
fight the underlying code - which is why I never released mine, it was too
much of a hack by the time it mostly worked.
http://trout.me.uk/perl/Class-DBI-Relationship-HasManyToMany-0.02.tar.gz
is one of the attempts, dunno if that's any use to you. Personally when we
encounter stuff like this we tend to find it's faster to upgrade the code to
DBIx::Class.
--
Matt S Trout Offering custom development, consultancy and support
Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +