加入" belongs_to"的表格的搜索结果另一个

时间:2014-05-09 14:24:42

标签: mysql perl belongs-to dbix-class

visits有许多visitsTasks属于tasks

我正在查看visitID表中的特定行(visits),并希望找到已完成的所有任务。在这些任务中,我想访问pathmode列(在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;
      }

taskNamevaluevisits_tasks列)可用。但我无法找到语法或缺少的关系,以便visitsTasks结果加入tasks


我用dia创建了一个UML图,用parsediasql将图形转换为mySQL ,并使用dbicdump填充DBIX ::类。

UML diagram

visitsTasks

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)
)

1 个答案:

答案 0 :(得分:0)

需要花更多时间在Cookbook上。连接列与原始列不在同一级别。

$vt->task_name->path #not $vt->path