Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest update (2.1.3) does not seem to allow DB:raw() for me as examples have shown #139

Open
bmcn99 opened this issue Jun 3, 2022 · 1 comment

Comments

@bmcn99
Copy link

bmcn99 commented Jun 3, 2022

My current relationship using compoships works well:
return $this->belongsTo('App\Models\PizzaPrice', ['pizza_id', 'size_id'], ['pizza_id', 'size_id']);

but after updating to 2.1.3 and altering it to use:
return $this->belongsTo('App\Models\PizzaPrice', ['pizza_id', DB::raw('size_id')], ['pizza_id', 'size_id']);
or
return $this->belongsTo('App\Models\PizzaPrice', ['pizza_id', DB::raw('table_name.size_id')], ['pizza_id', 'size_id']);

in order to test the new functionality it produces the following error:
array_key_exists(): The first argument should be either a string or an integer

Am I not using this correctly? My end goal would be a relationship that is a few degrees removed and look something like this:

return $this->hasMany('B',
	['foreignKey1', DB::raw('F.foreignKey2')], //or possibly providing a const value here
	['localKey1', 'localKey2']
)
->join('C','C.other_key','=','B.other_key');
->join('D','D.other_key','=','C.other_key');
->join('E','E.other_key','=','D.other_key');
->join('F','F.other_key','=','E.other_key');

But that will not work since it dies when trying to use DB::raw('F.foreignKey2'). Please let me know if I can provide any further information and thank you.

@erikn69
Copy link
Contributor

erikn69 commented Jun 20, 2022

#122

Hi, 2.1.3 feature works for hasOne, hasMany, fell free to make a PR for belongsTo
Also give the file and the line of the exception,
Did you try the inverse?

return $this->belongsTo('App\Models\PizzaPrice', ['pizza_id', 'size_id'], ['pizza_id', DB::raw('table_name.size_id')]);

Also try this erikn69@005a39c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants