[Catalyst] Re: Adding relationships to loaded CDBI models

James Tolley james at bitperfect.com
Tue Jun 21 15:10:24 CEST 2005


 > How do you explicitly define a might_have relationship in sql? :)

> I haven't gotten anything into code yet, but for a long time I've
> thought about using "SELECT COUNT(*) FROM table" to infer similar
> facts.  If you have 1,000 Person records and only 500 Spouse records,
> then obviously "Person might have Spouse".  OTOH, if you have 1,000
> Person records and 1,500 Offspring records, then it is less obvious
> that "Person might have Offspring".

I agree with Perrin that it's relatively easy to provide might_have
relationships, little or no inferring required. All you need is primary key
info and foreign key info, both of which are available (in mysql InnoDB at
least). Can we agree that where there is a single primary key column
referring to the primary key of another table, then that is a might_have
relationship? If so, let's patch Class::DBI::Loader::mysql. I will volunteer
to write the code, including tests.

The other thing on my mind is has_many mapping relationships. Can we also
agree that where there is a table with a two-field primary key in which each
field refers to the primary key of another table, then that is a has_many
mapping relationship? If so, let's write that as well. I'll be happy to do
it, if there's a consensus.

James




More information about the Catalyst mailing list