visits
有许多visitsTasks
属于tasks
。
我正在查看visitID
表中的特定行(visits
),并希望找到已完成的所有任务。在这些任务中,我想访问path
和mode
列(在tasks
表中)。
my $visitTasks = $visit->visits_tasks()->search(
{'me.subsection' => 'completed'},
{join => 'task_name' } # PROBLEM HERE
);
while(my $vt=$visitTasks->next()){
say Dumper($vt->get_columns());
# if completed is true then record the task
push @{$visit{Tasks}}, {taskName => $vt->task_name, path=>$vt->path, mode=>$vt->mode } if $vt->value == 1;
}
taskName
和value
(visits_tasks
列)可用。但我无法找到语法或缺少的关系,以便visitsTasks
结果加入tasks
我用dia
创建了一个UML图,用parsediasql
将图形转换为mySQL
,并使用dbicdump
填充DBIX ::类。
package lncddb3::Schema::Result::VisitsTask;
#...
=head2 task_name
Type: belongs_to
Related object: L<lncddb3::Schema::Result::Task>
=cut
__PACKAGE__->belongs_to(
"task_name",
"lncddb3::Schema::Result::Task",
{ taskName => "taskName" },
{
is_deferrable => 1,
join_type => "LEFT",
on_delete => "RESTRICT",
on_update => "RESTRICT",
},
);
package lncddb3::Schema::Result::Task;
# ...
=head2 visits_tasks
Type: has_many
Related object: L<lncddb3::Schema::Result::VisitsTask>
=cut
__PACKAGE__->has_many(
"visits_tasks",
"lncddb3::Schema::Result::VisitsTask",
{ "foreign.taskName" => "self.taskName" },
{ cascade_copy => 0, cascade_delete => 0 },
);
create table visits (
visitID int unsigned not null auto_increment ,
peopleID int unsigned ,
visitdate date ,
visitTime time ,
scanID varchar(50) ,
noShow bool ,
schedualedBy varchar(50) ,
checkedInBy varchar(50) ,
googleid varchar(50) ,
age double unsigned ,
onMeds varchar(20) ,
location varchar(50) ,
cohort varchar(50) default "control",
quality int ,
constraint pk_visits primary key (visitID)
)
create table visitsTasks (
peopleID int unsigned ,
visitID int unsigned ,
taskName varchar(50) ,
subsection varchar(50) ,
value varchar(50)
)
create table tasks (
taskName varchar(50) not null,
taskDesc char(200) ,
path varchar(300) ,
mode varchar(50) ,-- fMRI, PET, MEG,fMRI+eyetracking,eyetracking, etc
constraint pk_tasks primary key (taskName)
)