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_and_belongs_to_many_with_tenant does not include 3 arguments #206

Closed
Laykou opened this issue Sep 5, 2023 · 2 comments · Fixed by #207
Closed

has_and_belongs_to_many_with_tenant does not include 3 arguments #206

Laykou opened this issue Sep 5, 2023 · 2 comments · Fixed by #207

Comments

@Laykou
Copy link
Contributor

Laykou commented Sep 5, 2023

Original implementation of has_and_belongs_to_many is like:

def has_and_belongs_to_many(name, scope = nil, **options, &extension)

However has_and_belongs_to_many_with_tenant only includes these arguments:

def has_and_belongs_to_many_with_tenant(name, options = {}, &extension)

scope argument is missing here. Therefore when used like this on a model:

class User < ApplicationRecord
  has_and_belongs_to_many :personal_groups, -> { personal }, class_name: 'Group'
end

then it fails with:

Failure/Error: has_and_belongs_to_many :personal_groups, -> { personal }, class_name: 'Group'

ArgumentError:
  wrong number of arguments (given 3, expected 1..2)
# ./vendor/bundle/ruby/3.2.0/gems/activerecord-multi-tenant-2.3.0/lib/activerecord-multi-tenant/habtm.rb:11:in `has_and_belongs_to_many_with_tenant'

Laykou referenced this issue Sep 5, 2023
* Adds has_and_belongs_to_many featurewith tenant

* Fixes static code analysis

* Parameterizes field name

* Parameterizes field name
Laykou added a commit to Laykou/activerecord-multi-tenant that referenced this issue Sep 5, 2023
@serprex
Copy link
Collaborator

serprex commented Sep 5, 2023

Was this parameter added to ActiveRecord in the last few versions?

@Laykou
Copy link
Contributor Author

Laykou commented Sep 5, 2023

I see this has been already there even 7 years ago

serprex pushed a commit that referenced this issue Sep 7, 2023
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

Successfully merging a pull request may close this issue.

2 participants