Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

LocalKey not working with a HAS_ONE relationship #204

Closed
MrAtiebatie opened this issue May 7, 2014 · 4 comments
Closed

LocalKey not working with a HAS_ONE relationship #204

MrAtiebatie opened this issue May 7, 2014 · 4 comments

Comments

@MrAtiebatie
Copy link

I had the following database scheme:

users

  • id
  • name
  • language_id

languages

  • id
  • name

Now I have tried to make the relationship between language_id and languages.id:
ardent1

ardent2

But after an hour debugging I found out that he didn't used the localKey but just the primary key of the table, in the case of the user table it's 'id'. So I took a look in the source of Ardent and saw that the localKey parameter isn't sent to Model@hasOne while it is an (optional) parameter of the hasOne method of Laravel. Is this a bug? Because when I changed rule 316&317 in Ardent.php it worked:
ardent3

Thanks in advance

@VesninAndrey
Copy link

Also came across this feature. Please add the "localKey" for relations HAS_ONE, HAS_MANY and BELONGS_TO.

For those looking for a quick solution - make like issue author:

(start at line 313 in Ardent.php)
case self::HAS_ONE:
case self::HAS_MANY:
case self::BELONGS_TO:
$verifyArgs(['foreignKey', 'localKey']);
return $this->$relationType($relation[1], $relation['foreignKey'], $relation['localKey']);

@misilot
Copy link

misilot commented Jan 30, 2015

What would need to be done to get this included in a release?

@gg4you
Copy link
Contributor

gg4you commented Apr 19, 2015

Has this been included in a release?

@igorsantos07
Copy link
Member

this might be something that was added later and not looked into at the time of development.

Just wondering: is your field was language_id why is the local key only language? haha

igorsantos07 added a commit that referenced this issue May 9, 2015
localKey argument for relationships is now considered. closes #204
igorsantos07 added a commit that referenced this issue May 10, 2015
- Adding 'relation' param to BelongsTo relations
- Adding 'localKey' to MorphOne/MorphMany (refs #204)
- Creating MorphToMany/MorphedByMany relations, as per #232 / @mklenk
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants