is there a reason you don't want to use integers? your app can still work with (string) user_id if you want to, just create a new column and index it, let Laravel handle the relationship stuff with the integers.
auto increment is fine for me when i will make new app. the problem is the database is existing and we share the database with vfp desktop app and were planning to make a web app. sometimes there is a need for primary keys to be less predictable. =)
did you try this
// Reservation model
return $this->belongsTo('User', 'foreign_key', 'local_key');
FYI
DB::getQueryLog(); // array of executed queries
zenry said:
did you try this
// Reservation model return $this->belongsTo('User', 'foreign_key', 'local_key');
actually my models are config like this
class User extend Eloquent {
public $incrementing = false;
public function reservations()
{
return $this->hasMany('Reservation', 'user_id');
}
}
class Reservation extend Eloquent {
public $incrementing = false;
public function user()
{
return $this->belongsTo('User');
}
}
am i doing it wrong?
i get this log
[ {"query":"select * from `reservation` where `user_id` = ?","bindings":["22beb4892ba944c8b1895855e1d4d1ad"],"time":0.63},
{"query":"select * from `user` where `user`.`id` in (?)","bindings":[0],"time":0.45} ]
from your
DB::getQueryLog();
wtf! im so dumb! just need to put the 2nd param on my $this->belongsTo('User')
public function user(){
return $this->belongsTo('User', 'user_id');
}
thanks for helping! cheers!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community