Skip to content

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

@ellmetha

Description

@ellmetha

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions