Skip to content

Conversation

@seanpdoyle
Copy link
Contributor

The problem

Some has_many and has_one associations provided by APIs are "joined" by properties other than their id (or an overridden primary_key).

The proposal

By default, continue to infer the :foreign_key as self.class.element_name + "_id" and its :primary_key from the value of its primary key (returned by the id method).

When necessary, has_many declarations can declare :primary_key and :foreign_key options in the same style as Active Record's has_many associations.

The problem
---

Some `has_many` and `has_one` associations provided by APIs are "joined"
by properties other than their `id` (or an overridden `primary_key`).

The proposal
---

By default, continue to infer the `:foreign_key` as
`self.class.element_name + "_id"` and its `:primary_key` from the value
of its primary key (returned by the `id` method).

When necessary, `has_many` declarations can declare `:primary_key` and
`:foreign_key` options in the same style as [Active Record's `has_many`
associations][has_many].

[has_many]: https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_many
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

Successfully merging this pull request may close these issues.

1 participant