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

Stop using update_only to decide to show subform on create #3649

Conversation

myers
Copy link
Contributor

@myers myers commented Oct 6, 2023

Closes #2626

There seems to be some confusion here about what :update_only means in accepts_nested_attributes_for in Rails Admin. It is currently use to decide to show the subform for a child record when creating a new record. I don't think this is correct.

https://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html

For a one-to-one association, this option allows you to specify how nested attributes are going to be used when an associated record already exists. In general, an existing record may either be updated with the new set of attribute values or be replaced by a wholly new record containing those values. By default the :update_only option is false and the nested attributes are used to update the existing record only if they include the record’s :id value. Otherwise a new record will be instantiated and used to replace the existing one. However if the :update_only option is true, the nested attributes are used to update the record’s attributes always, regardless of whether the :id is present. The option is ignored for collection associations.

This PR no longer attempts to use update_only, and only looks at field.inline_add.

Also as a bonus removing an unless with || makes my Grug brain happy.

@mshibuya mshibuya merged commit 13c90fd into railsadminteam:master Oct 28, 2023
19 checks passed
@mshibuya
Copy link
Member

Totally makes sense, thank you for the PR 👍

jklimke added a commit to 3dcl/rails_admin that referenced this pull request Nov 28, 2023
* 'master' of github.com:railsadminteam/rails_admin:
  Tidy up gemfiles
  Bump jRuby
  Test against Mongoid 8
  Test against Rails 7.1
  Mitigate jRuby build failures
  Upgrade node and vite to fix the vite build
  Un-pin turbo-rails to fix Rails 6.1 builds
  Follow-up for railsadminteam#3555
  Resolved a problem with embedded mongoid documents and boolean selectors (railsadminteam#3555)
  Stop using update_only to decide to show subform on create (railsadminteam#3649)
  Follow-up for railsadminteam#3643
  Basic vite integration attempt (railsadminteam#3643)
  Support client-side dynamic scoping
  Fix Rubocop offense
  Revive the live demo
  Unlock webrick version
  Fix typo: tripple ==> triple (railsadminteam#3637)
  Replace &rdquo; entity with inline <q> element (railsadminteam#3636)
  Vulnerability fix: validate return_to param using request.host (railsadminteam#3627)
  Fix Rubocop offense
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.

fields.nested_form[:update_only] should always be false by default.
2 participants