DBIx :: Class :: ResultSet在多个唯一约束上更新或创建

时间:2011-06-10 11:06:03

标签: perl catalyst dbix-class

我想知道dbix

中的多个唯一约束是否有可​​能update_or_create

来自Cpan:

 my $cd = $schema->resultset('CD')->update_or_create(
    {
      artist => 'Massive Attack',
      title  => 'Mezzanine',
      year   => 1998,
    },
    { key => 'cd_artist_title' }
  );

我想做什么

   my $cd = $schema->resultset('CD')->update_or_create(
    {
      artist => 'Massive Attack',
      title  => 'Mezzanine',
      year   => 1998,
    },
    { key => {'cd_artist_title','year' }
  );

1 个答案:

答案 0 :(得分:4)

我明白了:您必须使用add_unique_constraint在Controller中定义唯一约束。