use lib '/var/www/Employees';
use DBConnect::DBConnect qw(getSchemaConnection);
BEGIN { $ENV{DBIC_TRACE} = 1 }
$schema = getSchemaConnection();
$salaries = $schema->resultset('Salary')->search(
{
'employees.emp_no'=>100000
},
{
join =>'employees'
}
);
print $emplyees->count;
我有两张表employees和salary,Salary is belongs_to employees 我喜欢用employees表中的员工编号搜索薪水
当我尝试运行它时,我收到以下错误
DBIx::Class::ResultSource::_resolve_join(): No such relationship employees on Salary at /var/www/Employees/Testing/3_simpleJoin.pl line 29
这是我的课程:
薪水:
package DAO::Schema::Result::Salary;
# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->add_columns(
"emp_no",
{ data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
"salary",
{ data_type => "integer", is_nullable => 0 },
"from_date",
{ data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 0 },
"to_date",
{ data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 0 },
);
__PACKAGE__->set_primary_key("emp_no", "from_date");
__PACKAGE__->belongs_to(
"emp_no",
"DAO::Schema::Result::Employee",
{ emp_no => "emp_no" },
{ is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
);
1;
这是我的员工课
package DAO::Schema::Result::Employee;
# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->add_columns(
"emp_no",
{ data_type => "integer", is_nullable => 0 },
"birth_date",
{ data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 0 },
"first_name",
{ data_type => "varchar", is_nullable => 0, size => 14 },
"last_name",
{ data_type => "varchar", is_nullable => 0, size => 16 },
"gender",
{ data_type => "enum", extra => { list => ["M", "F"] }, is_nullable => 0 },
"hire_date",
{ data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 0 },
);
__PACKAGE__->set_primary_key("emp_no");
__PACKAGE__->has_many(
"salaries",
"DAO::Schema::Result::Salary",
{ "foreign.emp_no" => "self.emp_no" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->has_many(
"titles",
"DAO::Schema::Result::Title",
{ "foreign.emp_no" => "self.emp_no" },
{ cascade_copy => 0, cascade_delete => 0 },
);
1;