Php 由于更新的表格上的_不明确,雄辩更新()失败

Php 由于更新的表格上的_不明确,雄辩更新()失败,php,laravel-4,eloquent,Php,Laravel 4,Eloquent,好的,这个问题源于Laravel 4.1.23的安装。我正在尝试对包含联接的查询使用Elount update()方法更新多个记录: ChildSchoolYear::whereNull('exit_date')-> join('school_years', 'child_school_years.school_year_id','=','school_years.id')-> update(array('child_school_years.exit_date'=>'`sch

好的,这个问题源于Laravel 4.1.23的安装。我正在尝试对包含联接的查询使用Elount update()方法更新多个记录:

ChildSchoolYear::whereNull('exit_date')->
join('school_years', 'child_school_years.school_year_id','=','school_years.id')->
update(array('child_school_years.exit_date'=>'`school_years`.`end_date`',
'child_school_years.editor_id'=>$userId))
Laravel正在为我上面提供的查询内容生成正确的SQL,但是生成的完整SQL语句是

update `child_school_years` 
inner join `school_years` on `child_school_years`.`school_year_id` = `school_years`.`id` 
set `child_school_years`.`exit_date` = `school_years`.`end_date`,
`child_school_years`.`editor_id` = 2, 
`updated_at` = 2014-08-15 02:00:33 where `exit_date` is null) 
这将起作用,但自动添加的
updated_at
字段同时存在于child_school_years和school_years表中,因此Laravel添加该字段会触发异常
完整性约束冲突:字段列表中的1052列“updated_at”不明确


有没有关于如何驯化最新的作品的建议?我很乐意更新该字段,但如果有可能消除它,如果必要的话,我将不使用它。

没有办法改变雄辩的行为,即使在列中调整
updated\u也无济于事,因此您需要使用简单的
查询\Builder
,如前所述,或者使用以下方法之一,我觉得更好一点:

// easiest way
ChildSchoolYear::whereNull('exit_date')
  ->join('school_years', 'child_school_years.school_year_id','=','school_years.id')
  ->getQuery()  // get underlying base Query\Builder
  ->update(
    array(
      'child_school_years.exit_date'  => '`school_years`.`end_date`',
      'child_school_years.editor_id'  => $userId,
      'child_school_years.updated_at' => Carbon\Carbon::now(),
    )
  );

// also would work, temporary turn off auto timestamps
with($model = new ChildSchoolYear)->timestamps = false;

// above is the same as:
// $model = new ChildSchoolYear;
// $model->timestamps = false;

$model->whereNull('exit_date')
  ->join('school_years', 'child_school_years.school_year_id','=','school_years.id')
  ->update(
    array(
      'child_school_years.exit_date'  => '`school_years`.`end_date`',
      'child_school_years.editor_id'  => $userId,
      'child_school_years.updated_at' => Carbon\Carbon::now(),
    )
  );

getQuery()语句来自哪里?我在任何地方都找不到它。这两种方法看起来都很有希望,但如果我能获得更多信息,我更喜欢使用getQuery()。实际上,我还对with()函数的定义位置感兴趣。在Laravel.com的在线文档中,我似乎找不到任何一个。查看源代码,这是学习框架的最好方法。它也有很好的文档记录
getQuery
这里是
Eloquent\Builder
s方法,而
with
只是
Lightlight\Support\helpers.php中定义的一个小助手。php
-helpers文档中的最后一个:感谢您的参考。我想我已经被PHP文档给宠坏了,它通常解释了每个函数的基础知识——浏览Laravel源代码可以让您了解一些事情,但到目前为止,我很少发现它实际上直接解释了很多内容。我还发现,有时在网上浏览源代码非常困难。尽管如此,这些建议仍然有用。谢谢。不,不是在线来源。获取应用程序中的代码。如果你想了解事情是如何运作的,那么在线API文档是非常无用的。一个解决方法是使用查询生成器而不是雄辩的。请参考下面的链接