Support the ongoing development of Laravel.io →
Configuration Database Eloquent
Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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. =)

Last updated 2 years ago.
0

did you try this

// Reservation model
return $this->belongsTo('User', 'foreign_key', 'local_key');
Last updated 2 years ago.
0

FYI

DB::getQueryLog(); // array of executed queries
Last updated 2 years ago.
0

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(); 
Last updated 2 years ago.
0

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!

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

jrsalunga jrsalunga Joined 25 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.