Php Laravel查询生成未正确绑定参数
查询生成器似乎以错误的顺序绑定了参数 我的问题是:Php Laravel查询生成未正确绑定参数,php,mysql,laravel,laravel-4,Php,Mysql,Laravel,Laravel 4,查询生成器似乎以错误的顺序绑定了参数 我的问题是: $query = DB::table('jobs'); $query->whereIn( 'status_id', $status_array); $this_query->leftjoin( 'attribute_text_data', function($join) use ( $attribute_id, $attribute_value ){ $join->on( 'jobs.job_id', '=',
$query = DB::table('jobs');
$query->whereIn( 'status_id', $status_array);
$this_query->leftjoin( 'attribute_text_data', function($join) use ( $attribute_id, $attribute_value ){
$join->on( 'jobs.job_id', '=', 'attribute_text_data.job_id' )
->where( 'attribute_id', '=', $attribute_id )
->where( 'attribute_value', '=', $attribute_value );
});
当我运行这个程序时,我注意到没有返回正确的结果。因此,我输出了原始查询,但参数似乎没有按正确的顺序绑定:
select distinct `jobs`.`job_id` as `job_id`, `job_title`, `job_due_date`, `status_id`, `assigned_to_contact_id`, `jobs`.`account_id`, `billing_account_id`, `attribute_text_data`.`attribute_value` as `attribute_value_text`
from `jobs` left join `attribute_text_data`
on `jobs`.`job_id` = `attribute_text_data`.`job_id`
and `attribute_id` = ?
and `attribute_value` = ?
where `status_id` in (?, ?, ?, ?)
[bindings] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 4 ( attribute_id )
[5] => hourly (attribute_value )
)
似乎由于status是首先添加到查询的,所以它的参数是首先添加到bindings数组的。然后添加了属性绑定。但似乎查询随后被重新排列,参数的访问顺序不正确
这是一个bug,还是我的查询语法有问题
注意-很难将查询的状态部分移动到属性部分之后,但可以作为最后手段。我觉得应该正确地应用绑定,而不是试图找到解决办法。您使用的是哪个版本的Laravel?在最新的4.2版本中,它对我来说效果很好