Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

has_many :through would supose a real improvement #411

Open
ribanez7 opened this issue Aug 19, 2016 · 1 comment
Open

has_many :through would supose a real improvement #411

ribanez7 opened this issue Aug 19, 2016 · 1 comment

Comments

@ribanez7
Copy link

In an scenario, very recurrent by the way, where there's a database containing the users' table and then, diferent databases from diferent apps relying on the first db for the users info, it is impossible to define independent roles.
Example:
APP1 (with DB 1) has rolify, the roles table, and the join table roles_users, but not users.
APP2 (with DB 2) has the table users, and also roles and roles_users.

When assigning a role on APP1, it is impossible to declare that the join table to be used should be the one in APP1, it defaults to the one on the lhs due to the has_and_belongs_to_many behavior.

has_many :through would allow to specify this on the model.

I know this feature was "work in process", but which is the status?
Although the best solution would be to have the ability to define a model for the join_table of has_and_belongs_to_many... but don't think this will be done ever.

Thanks in advance!

@januszm
Copy link

januszm commented Jul 8, 2022

As currently Rubocop thinks this is offense

Rails/HasAndBelongsToMany: Prefer has_many :through to has_and_belongs_to_many
    has_and_belongs_to_many :users, join_table: :users_roles
Rails/CreateTableWithTimestamps: Add timestamps when creating a new table.
    create_table(:users_roles, id: false) do |t|

I looked here on Github and I can see that this topic is already open for a solid couple of years. To turn it into a has_many through with a model, would it be enough if we simply modify the db migration file by adding id, timestamps and replace the relation with has_many through after the file is generated with rolify? Or do you guys think it'd require more changes in the gem code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants