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

[Proposal] Configurability of key column names using a BelongsToMany relationship #406

Closed
alberto-bottarini opened this issue Feb 7, 2017 · 4 comments

Comments

@alberto-bottarini
Copy link

alberto-bottarini commented Feb 7, 2017

Using a hasOne, hasMany and belongsTo, I can configure every column name involved into the relationship, both the current table column name and the related table column name using extra optional parameters.

e.g. the constructor of HasOneOrMany relationship accepts a lot of parameters

public function __construct(Builder $query, Model $parent, $foreignKey, $localKey)

Using belongsToMany this configurability is not available. If the current table doesn't use primary key as join column with pivot table, I cannot use this relationship (unless force a runtime change of primaryKey property).

e.g.

users table
- id : primary
- email

roles table
- id : primary
- name

role_user
- user_email
- role_id

I used to work with a lot of legacy db, and I found this feature very useful. I've got to implement this behavior a lot of time using different approaches, based on the different contexts.
If you think that having more optional parameters on BelongsToMany will be a good idea, i could implement and test a more abstract approach to allow everyone to use this.

@alberto-bottarini alberto-bottarini changed the title [Proposal] Configurability of foreign keys using a BelongsToMany relationship [Proposal] Configurability of column name using a BelongsToMany relationship Feb 7, 2017
@alberto-bottarini alberto-bottarini changed the title [Proposal] Configurability of column name using a BelongsToMany relationship [Proposal] Configurability of key column names using a BelongsToMany relationship Feb 7, 2017
@alberto-bottarini
Copy link
Author

Here is my fork's commit about this feature:

https://github.com/alberto-bottarini/framework/commit/10458d8299a8fbc27136b698161e36711cbd3d15

What do you think?

@arubacao
Copy link

arubacao commented Feb 12, 2017

alberto-bottarini/framework@10458d8 looks like a breaking change

@Garbee
Copy link

Garbee commented Feb 12, 2017

If you have a working state send a PR to master. Taylor reviews PRs faster than internals discussion.

It simply can't go into an existing version since it is a BC break. But, if Taylor will allow it to work it can get added into future releases of 5.x most likely.

@alberto-bottarini
Copy link
Author

You are right. It's a breaking change, I've made a mistake committing it to 5.4.

Thanks for your support :)

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

4 participants