[Feature] `accepts_nested_attributes_for` with primary key alternative

8 views
Skip to first unread message

Nick Rivadeneira

unread,
Aug 5, 2019, 11:36:08 AM8/5/19
to Ruby on Rails: Core
In our public API, we use a UUID for record identifiers, however our primary key internally is the default incrementing integer in Postgres. I'd like to submit a PR that adds an option to `accepts_nested_attributes_for` that would change which key is being queried on, but doesn't require a change of `primary_key` in the model.

Would this get accepted? If so, I'm interested in opinions on a good name for the option. Could be as simple as `:primary_key`, similar to how `belongs_to` has an option for `:primary_key` which does not require a primary key change in the associated model.

Kevin Gnadinger

unread,
Aug 5, 2019, 12:54:53 PM8/5/19
to rubyonra...@googlegroups.com
I support this and am surprised it isn't already implemented. Public-facing ID's and internal PKs is a pretty common architecture. 

On Mon, Aug 5, 2019 at 9:36 AM Nick Rivadeneira <nicholas.r...@gmail.com> wrote:
In our public API, we use a UUID for record identifiers, however our primary key internally is the default incrementing integer in Postgres. I'd like to submit a PR that adds an option to `accepts_nested_attributes_for` that would change which key is being queried on, but doesn't require a change of `primary_key` in the model.

Would this get accepted? If so, I'm interested in opinions on a good name for the option. Could be as simple as `:primary_key`, similar to how `belongs_to` has an option for `:primary_key` which does not require a primary key change in the associated model.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/ecc0ce4d-cf39-44cc-8c56-67ec27980b13%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages