in reply to Class DBI many to many
One important remark in the documentation:
When setting up the relationship the foreign class's has_a() declarations are examined to discover which of its columns reference our class. (Note that because this happens at compile time, if the foreign class is defined in the same file, the class with the has_a() must be defined earlier than the class with the has_many(). If the classes are in different files, Class::DBI should usually be able to do the right things, as long as all classes inherit Class::DBI before 'use'ing any other classes.)
So this should work by reordering the declarations:
package MyDictionary::En_To_Sk MyDictionary::En_To_Sk->columns(Primary => qw/id/); MyDictionary::En_To_Sk->columns(Essential => qw/eng_id sk_id/); # Declare the relationships MyDictionary::En_To_Sk->has_a('eng_id' => "MyDictionary::Engword"); MyDictionary::En_To_Sk->has_a('sk_id' => "MyDictionary::Skword"); package MyDictionary::Engword MyDictionary::Engword->columns(Primary => qw/id/); MyDictionary::Engword->has_many("translations", 'MyDictionary::En_To_S +k', 'eng_id'); package MyDictionary::Skword MyDictionary::Skword->columns(Primary => qw/id/); MyDictionary::Skword->has_many("translations", 'MyDictionary::En_To_Sk +', 'sk_id');
I suppose you have defined the other columns. The construction "['MyDictionary::En_To_Sk' => 'engword']" in the 'has_many' function in the class 'MyDictionary::En_To_Sk' is only necessary when the values in 'eng_id' and 'sk_id' are not the primary keys used in the classes 'package MyDictionary::Engword' and 'package MyDictionary::Skword'.
Hopes this helps.
Martell
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Class DBI many to many
by zooey (Initiate) on Jun 19, 2011 at 22:15 UTC |