[Dbix-class] Determining FKs in relationship_info->{cond}

Christopher H. Laco claco at chrislaco.com
Tue Jun 20 20:45:31 CEST 2006


What's the most sane way to determine all of the "foreign." FK field
names for a giving relationship?

For something simple like this:

> __PACKAGE__->has_many(items => 'Handel::Schema::Cart::Item', {'foreign.cart' => 'self.id'});

relationship_info->{cond} is pretty straight forward. Getting the FK
column name is a matter of 'keys %{relationship_info}', and stripping
'foreign.' from the results.

But considering how complex an SQLT $condition statement can really get,
that solution will fail in short order.

I know when you add_to_$relname, it fills in the foreign key fields
automatically for declared relationships.... what method does it use to
determine what all of the FK fields are?

As for the scenario, I'm copying items from one cart to another, and I
only want to copy the items fields that aren't PKs or FKs. PKs are
easily had via primary_columns(), and I can get the condition statement
for the item relations from relationship_info. What I'm struggling with
is safely getting all of ht epossible foreign. column names.

-=Chris

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: OpenPGP digital signature
Url : http://lists.rawmode.org/pipermail/dbix-class/attachments/20060620/e875e1b1/attachment.pgp 


More information about the Dbix-class mailing list