laravel-acquaintances icon indicating copy to clipboard operation
laravel-acquaintances copied to clipboard

Unable to specifiy foreign key column name

Open chazzka opened this issue 1 year ago • 1 comments

The based-upon package laravel-follow deals with different config attribute for foreign key (changing the default "user_id").

This is useful when using different Model for auth (instead of the default User)

This package unfortunately omits it, making different foreign key impossible to set, eventually causing errors in autogenerated queries. (interactions.foreign_key_name).

Now, if user wants a different foreign key naming, he can directly specify in migration, but later generated scripts will still respect the previous configuration.

Please consider adding similar configuration as in previous package on this line

chazzka avatar Jun 27 '23 10:06 chazzka

Hey Chazzka, thanks for your input, and yes for sure! this is something fairly easy to implement, I will take a look at it in the upcoming weeks.

Thanks for pointing it out and for your explanation 🙌

mkwsra avatar Jun 27 '23 12:06 mkwsra

Hello @mkwsra, i was facing this error. With the documentation I thought that just by adding the traits CanXXX like CanLike it will work with any model.

  • It would be interesting than the interaction table has two morphTo and interactions would work with any model to any model. The friendships table it already works that way.
  • On the other hand now on the config has interactions_user_id_fk_column_name but is not used in the migration for the interactions table. Also the migration use config('auth.providers.users.model') insted of config acquaintances.models.user

For now i directly specify the column name in migration alredy created.

adriallongarriu avatar Jun 06 '24 16:06 adriallongarriu

Hi Adrià, thanks for pointing this out, we have to do something about this (someone of us)

mkwsra avatar Jun 07 '24 07:06 mkwsra

@mkwsra later i will make a PR modifying the migration and the function isRelationExists that uses 'user_id' to use the variables in config file.

The option to use two morphTo relation will be cool but will require more time and will introduce breaking changes.

adriallongarriu avatar Jun 07 '24 10:06 adriallongarriu