laravel-mongodb: hasMany or hasOne doesnt work without getIdAttribute
This issue has been around, can you guys provide a documentation how to properly make sure things work in hasMany and hasOne
for now using this to make sure hasMany and hasOne work
public function getIdAttribute($value = null)
{
return $value;
}
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 1
- Comments: 16 (15 by maintainers)
I agree that using ObjectIds is a good practice for foreign keys. I tried to implement it, but found issues with how the parent Eloquent classes work with foreign keys. They assume every primary/foreign key can be represented as a string. This need in-deep investigation to find how we can implement it in a way that we can maintain in a long-term, without breaking existing application that rely on string foreign keys.
There is no plan for now.
I think you dont have a test for this. For data consistency we always save the real objectid not a string representation on the collection.
This Fails hasMany
This make the relationship hasMany work
User.php
Hopefully it could be fix, this I think should be important especially for some people having different codebases.
version 4.1.3, I did it work but needs to add getIdAttribute to each models. I pass in custom keys since it convert camelCase keys into snake_keys