-
Notifications
You must be signed in to change notification settings - Fork 405
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
Support has_many :through instead of just only has_and_belongs_to_many #181
base: master
Are you sure you want to change the base?
Conversation
+1 for using Whats the reason for My use case: resourcify
has_many :licensees,
class_name: 'User',
through: :roles,
source: :users,
conditions: { roles: { name: 'licensee' } } |
has_and_belongs_to_many :roles, rolify_options | ||
# Option to support has_many :through | ||
has_many_through_table = options.delete(:has_many_through) | ||
if has_many_through_table |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Thanks for this PR. I plan to switch from HABTM to |
👍 |
@kidlab this will allow us to add validations on Role, right? |
# Option to support has_many :through | ||
has_many_through_table = options.delete(:has_many_through) | ||
if has_many_through_table | ||
self.role_join_table_name = has_many_through_table |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I need to use that variable here :)
@enricostano Yup, but the main purpose of this is to allow us use a custom joining table (e.g, |
👌 |
is anybody using this branch in a production environment? |
@kidlab Is this PR all setup and working? I see that the Travis build passes but it's been a while so I was wanting some more info. This would be a good feature to include in Rolify. |
@wldcordeiro I made quick look on blame in changed method. |
Any progress on this? What's holding it up? |
Anyone still interested in this? I would love to create a relation and scopes :through roles.
Boo, this was wrong, see next comment |
Scratch my last comment, you can remove class_name, but must be sure source_type is capitalized to match the model name and it seems to create good SQL:
|
Hi guys, |
Long time has past, but i think this is still relevant |
SUMMARY:user.rb
let's you do
post.rb
let's you do
This is something that should be 100% included in the gem, or in the description |
Hey! Any news with this PR? |
I'd like to ship this! I'm not sure of the migration path for folks with existing Rolify instances or if we need to change generators. I think I would rather we default to |
has_and_belongs_to_many
works well for most of use-cases, but it's annoying if we want to:"#{self.to_s.tableize.gsub(/\//, "_")}_#{self.role_table_name}"
created_at
andupdated_at
For the above reasons, I added one more option called
has_many_through
to allow developer can use a customized join table byhas_many :through
association.