Thread Rose::DB::Object - Relationships
(8 answers)
Opened by roooot at 2010-04-02 15:32
Hi Leute,
ich bekomm es einfach nicht auf die Rolle. Ich will ![]() Ich habe 2 Tabellen: users und users_contact (One-To-One Beziehung) Code: (dl
)
1 CREATE TABLE IF NOT EXISTS `users` ( Wie man sieht, zeigt der Primary_Key von users_contacts (user_id) auf id in der Tabelle users. Ok. PhpMyAdmin erkennt die Beziehung auch. Nun habe ich meine Tabellenkonfiguration aufgestellt, damit Rose::DB::Object damit arbeiten kann. Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 package User; use strict; use base qw(DB::Object); __PACKAGE__->meta->setup ( table => 'users', columns => [ id => { type => 'integer', not_null => 1 }, name => { type => 'varchar', length => 32, not_null => 1 }, password => { type => 'varchar', length => 40, not_null => 1 }, password_forcechange => { type => 'enum', check_in => [ 'Y', 'N' ], not_null => 1 }, last_ip => { type => 'varchar', length => 15 }, last_login => { type => 'timestamp' }, ], primary_key_columns => [ 'id' ], unique_key => [ 'name' ], foreign_keys => [ ], relationships => [ contact => { type => 'one to one', class => 'User::Contact', column_map => { id => 'user_id' }, }, ] ); 1; package User::Contact; use strict; use base qw(DB::Object); __PACKAGE__->meta->setup ( table => 'users_contact', columns => [ user_id => { type => 'integer', not_null => 1 }, email => { type => 'varchar', length => 128 }, homepage => { type => 'varchar', length => 256 }, phone => { type => 'text', length => 65535 }, messenger => { type => 'text', length => 65535 }, ], primary_key_columns => [ 'user_id' ], relationships => [ user => { type => 'one to one', class => 'User', column_map => { 'user_id' => 'id' }, }, ], ); 1; Rufe ich jetzt Code (perl): (dl
)
User->new(id=>1)->load->contact->email; Code: (dl
)
Can't locate object method "meta" via package "User::Contact" at /usr/share/perl5/Rose/DB/Object/MakeMethods/Generic.pm line 19 Ich habe absolut keine Ahnung mehr was hier los ist. Bin für jede Hilfe dankbar. Viele Grüße Viele Grüße :)
|