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 Support #466

Closed
muzamiluddin opened this issue Jan 21, 2015 · 7 comments
Closed

Has And Belongs To Many Support #466

muzamiluddin opened this issue Jan 21, 2015 · 7 comments

Comments

@muzamiluddin
Copy link

This is not a bug but a question.
I am able to restore has_many associations to a previous version but I am looking for a way to restore 'has and belongs to many' associations for an object.

Does paper trail support it? the only way I can think of as of now is to add column which stores the ids of habtm relationship. Is there an elegant way for this?

@batter
Copy link
Collaborator

batter commented Jan 21, 2015

@bli - did the work that was merged from #439 address this? I don't believe it did,and I think it would be even more complex, but I'm not certain?

@bli
Copy link
Contributor

bli commented Jan 21, 2015

No, I don't think it did either. But I think a Has And Belongs to Many association can be easily converted to a Has Many Through one.

@batter
Copy link
Collaborator

batter commented Jan 29, 2015

Good point, @Muzamil, though not quite as clean, you could use a join table and use has_many :through, which is supported for reification.

@bli
Copy link
Contributor

bli commented Jan 29, 2015

Exactly, and if I am not wrong, the join table is already there if you are using Has And Belongs To Many. You only need to add a model class for it and change the association type.

@muzamiluddin
Copy link
Author

Yes, Sounds good but as of now we had like 4-5 habtm relationships and we were not looking to change habtm to has many through.

So we took the route of

  1. Adding an additional column to 'versions' table
  2. Whenever a version record gets created for an object, we were updating the new column with the ids of habtm relationships.
  3. While retrieving the version, we were constructing the habtm relationship back.

Thank you for your support.

@neeraj-joshi01
Copy link

The thing I am addressing in Issue #530 is having a has many through relationship from table A to C through B, and then having a one to many relationship between table B and C.

In this case, the intermediate through model will not be having foreign keys of both the tables as in a proper many-many relationship and,
the existing code checks for the foreign key of the association in the intermediate through model which can't be there in a One to Many Relationship in my Example.

@jaredbeck
Copy link
Member

I'm going to go ahead and close this because we're really close to merging #771 which implements HABTM support.

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

5 participants