Notifynder icon indicating copy to clipboard operation
Notifynder copied to clipboard

Add config option for model owner key

Open wizston opened this issue 7 years ago • 9 comments

Option to set owner key in config for one to many relationship when polymorphic is not set to true for cases where user may have different key/table structure for their model.

wizston avatar May 12 '17 14:05 wizston

Coverage Status

Coverage decreased (-3.8%) to 86.616% when pulling e8c5a1ddb35d2de6d1ee1c973efbdd99d0b87171 on wizston:model-owner-key-config into 0d536e63ec00984353dda6ec8ea3d524e42cd822 on fenos:master.

coveralls avatar May 12 '17 14:05 coveralls

@Gummibeer That doesn't address the purpose of this PR. This PR is to provide the option to set the foreign key in your own Model.

wizston avatar May 13 '17 12:05 wizston

@wizston and this is what this method returns. The method will return the key name of the related model - so in general id or any other value if you have changed this. Putting this directly in the config is, for me, overhead cause it will duplicate the configuration work.

Gummibeer avatar May 13 '17 12:05 Gummibeer

@Gummibeer How would you advice in a situation where my model uses "user_id" column name instead of "id"? The the method returns the key name not set the key name. You wouldn't advice that i change my model relationship column name to id cause of the library, while there could be someone out there that communicated with some external data with any structure. I think adding it in the config would solve lots of these issues.

wizston avatar May 13 '17 12:05 wizston

Ok, what we need is the primary key of the other "user" model - this is by default id but can be changed to whatever you like - on the model and in database. The primary key of the user model is returned by his getKeyName() method. So yes, this could be a case where some work would be great - but I don't see the point why to introduce a new config value if it is possible to solve it by native laravel methods!? https://laravel.com/api/5.1/Illuminate/Database/Eloquent/Model.html#method_getKeyName

Gummibeer avatar May 13 '17 16:05 Gummibeer

Thanks @Gummibeer, I just adjusted the commit.

wizston avatar May 14 '17 12:05 wizston

Coverage Status

Coverage decreased (-3.7%) to 86.667% when pulling 8767a15d6b99a250733dde7c859e7c25fc15d664 on wizston:model-owner-key-config into 0d536e63ec00984353dda6ec8ea3d524e42cd822 on fenos:master.

coveralls avatar May 14 '17 12:05 coveralls

Can you please fix the failed checks and in best case add an unittest for it!?

Gummibeer avatar May 14 '17 13:05 Gummibeer

https://travis-ci.org/fenos/Notifynder/jobs/232078189

Needs a review

Gummibeer avatar May 17 '17 14:05 Gummibeer