sittercity/sprig

HasMany relationship uses incorrect foreign key

Closed this issue · 2 comments

In 1581314#L2R396, $model->fk() is used instead of $this->fk() to retrieve the foreign key to use for has-many relationships.

For example, for two models (model and related_model) with a has-many relationship, the following select query is generated when accessing the related model ($model->related_models):

SELECT ... FROM `related_models` WHERE `related_model_id` = 1

When it should be:

SELECT ... FROM `related_models` WHERE `model_id` = 1

Fixed by 61e8cc7

Now that I see the fix, I remember again that I wanted to bring up this issue for a long time... :) But I fixed it myself and then forgot about it... Sorry for that and thanks for fixing! :)