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

Document Support for has_and_belongs_to_many (HABTM) tables #34

Open
prem-prakash opened this issue Nov 10, 2015 · 3 comments
Open

Document Support for has_and_belongs_to_many (HABTM) tables #34

prem-prakash opened this issue Nov 10, 2015 · 3 comments

Comments

@prem-prakash
Copy link

Is it possible to add support to has_and_belongs_to_many tables that has no model ?

@pjambet
Copy link
Contributor

pjambet commented Nov 30, 2015

Hi,

This is currently not supported (I guess the README could be more explicit about this), as we use model classes to generate the seed file.

I think this would be a great feature, but sadly I can't guarantee that I'll have time to work on this anytime soon.

As usual, I'd be very happy to take a look at a PR of you want to implement this feature :)

@tbloncar
Copy link
Contributor

Dug into this a bit this evening, and it appears that the has_and_belongs_to_many join table does actually get a pair of implicit backing models. Given the following:

class Product
  has_and_belongs_to_many :categories
end

class Category
  has_and_belongs_to_many :products
end

We get two backing HABTM models: Product::HABTM_Categories and Category::HABTM_Products. As far as I can tell (having implemented a test for this on my fork), registering either of these models should do the trick.

SeedMigration.register Category::HABTM_Products

I'd be happy to submit a PR with the test and some documentation for this.

@pboling pboling changed the title Support to has_and_belongs_to_many tables Document Support for has_and_belongs_to_many (HABTM) tables Feb 21, 2023
@pboling pboling self-assigned this Feb 21, 2023
@pboling
Copy link
Owner

pboling commented Feb 22, 2023

@tbloncar still interested in submitting a PR for this?

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

No branches or pull requests

4 participants