mysql - Foreign key relationship methods deferred and never created in RDBO -
i'm playing rosedb::object on employees test dataset, , reason, can't foreign key relationships ('department' , 'employee') work on deptemp object. (class structure below).
when try $e->dept_emp->[0]->department
, get:
can't locate object method "department" via package "my::fakeemployees::deptemp" methods following relationships , foreign keys deferred , never created in class my::fakeemployees::deptemp. type name ---- ---- foreign key department foreign key employee
i'm sure have set wrong in class structure, what?
class structure (some classes omitted clarity):
i created various objects using instructions in rdbo tutorial:
package my::fakeemployees::employee; use strict; use base qw(my::fakeemployees::db::object); __package__->meta->setup( table => 'employees', columns => [ emp_no => { type => 'serial', not_null => 1 }, birth_date => { type => 'date', not_null => 1 }, first_name => { type => 'varchar', length => 14, not_null => 1 }, last_name => { type => 'varchar', length => 16, not_null => 1 }, gender => { type => 'enum', check_in => [ 'm', 'f' ], not_null => 1 }, hire_date => { type => 'date', not_null => 1 }, ], primary_key_columns => ['emp_no'], 'relationships' => [ 'departments' => { 'type' => 'many many', 'map_class' => 'my::fakeemployees::deptemp', }, 'dept_emp' => { 'type' => 'one many', 'class' => 'my::fakeemployees::deptemp', 'column_map' => { 'emp_no' => 'emp_no' }, }, 'dept_manager' => { 'type' => 'one many', 'class' => 'my::fakeemployees::deptmanager', 'column_map' => { 'emp_no' => 'emp_no' }, }, 'salaries' => { 'type' => 'one many', 'class' => 'my::fakeemployees::salary', 'column_map' => { 'emp_no' => 'emp_no' }, }, 'titles' => { 'type' => 'one many', 'class' => 'my::fakeemployees::title', 'column_map' => { 'emp_no' => 'emp_no' }, }, ], ); __package__->meta->make_manager_class('employees'); 1; package my::fakeemployees::deptemp; use strict; use base qw(my::fakeemployees::db::object); __package__->meta->setup( table => 'dept_emp', columns => [ dept_no => { type => 'character', not_null => 1 }, emp_no => { type => 'integer', not_null => 1 }, from_date => { type => 'date' }, to_date => { type => 'date' }, ], primary_key_columns => [ 'emp_no', 'dept_no' ], foreign_keys => [ department => { class => 'my::fakeemployees::departments', key_columns => { dept_no => 'dept_no' }, }, employee => { class => 'my::fakeemployees::employees', key_columns => { emp_no => 'emp_no' }, }, ], ); __package__->meta->make_manager_class('dept_emp'); 1; package my::fakeemployees::department; use strict; use base qw(my::fakeemployees::db::object); __package__->meta->setup( table => 'departments', columns => [ dept_no => { type => 'character', length => 4, not_null => 1 }, dept_name => { type => 'varchar', length => 40, not_null => 1 }, ], primary_key_columns => ['dept_no'], unique_key => ['dept_name'], 'relationships' => [ 'employees' => { 'type' => 'many many', 'map_class' => 'my::fakeemployees::deptemp', }, ], ); __package__->meta->make_manager_class('departments'); 1;
your foreign key has typo:
foreign_keys => [ department => { class => 'my::fakeemployees::departments',
that should 'department', not 'departments'
Comments
Post a Comment