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

Add support for custom through models for many-to-many fields #13

Open
ellmetha opened this issue Jul 7, 2021 · 0 comments
Open

Add support for custom through models for many-to-many fields #13

ellmetha opened this issue Jul 7, 2021 · 0 comments

Comments

@ellmetha
Copy link
Member

ellmetha commented Jul 7, 2021

Description

Right now an intermediary join table is automatically created for each many-to-many field definition. Ideally we should try to support the use of many-to-many fields involving custom through models, which can be necessary if other fields need to be defined as part of the many-to-many relationship.

The issue with a custom through model is that it would be necessary to introspect the specified model in order to identify what is the "origin" foreign key and the "destination" foreign key. Ideally we should find a way to ensure that this is something that is explicitly defined as part of the many-to-many field definition:

class Post < Marten::Model
  # Other fields...

  field :tags, :many_to_many, to: Tag, through: CustomPostTags, source: :field1, target: :field2
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant