Skip to content

Belongs To Many with custom foreign key #91

@lasseebert

Description

@lasseebert

I have tried using this gem and belongs_to_many for the first time.

In my case I want to use it on a non-default primary key (short_id instead of id), so I define it like this:

belongs_to_many :tags, primary_key: :short_id, foreign_key: :tag_short_ids

This works fine, e.g. when using preload and calling tags on my model. However, if I try to set the tags with tags=, it uses the id column of the tags instead of the short_id.

On another note: I think there is a mistake in the wiki page for belongs_to_many where the descriptions for primary_key and foreign_key seems to be swapped in the options section.

Thanks for an awesome gem!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions