1
我没有使用自动增量的ID,而是使用32个字符的唯一ID。所以,当我创建一个关系查询,即时得到一个空的,因为我的FK期待INT 我的模型Laravel:如何将主键和外键设置为字符串
class User extend Eloquent {
public $incrementing = false;
}
class Reservation extend Eloquent {
public $incrementing = false;
}
所以,当我查询这个
$reservations = Reservation::with('user')->where('user_id', '=', '22beb4892ba944c8b1895855e1d4d1ad')->get();
i could not retrieve the users information but the reservations info is working fine
when i try to listen for query. eg:
Event::listen('illuminate.query', function($query, $bindings, $time, $name){
var_dump($query);
var_dump($bindings);
});
我得到这个
string(46) "select * from `reservation` where `user_id` = ?"
array(1) {
[0]=>
string(36) "22beb4892ba944c8b1895855e1d4d1ad"
}
string(53) "select * from `user` where `user`.`id` in (?)"
array(1) {
[0]=>
int(0)
}
问题是在第二个查询我无法检索用户信息,因为user.id期待int。
太棒了!有用!只需要从我的$ this-> belongsTo('User')'中输入第二个参数'user_id'。非常感谢! – jrsalunga