You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've found an issue where model.has_many_polymorphic_models.where(condtion:value).first_or_initialize does not pass condition:value to the initialized polymorphic_model, whereas model.has_many_models.where(condtion:value).first_or_initialize passes condition:value to the initialized has_many_model.
The workaround is to use model.has_many_polymorphic_models.find_or_initialize_by(condition:value). But the issue of knowing where your polymorphic first_or_initialize calls are leads to confusing "Why is this nil?!" bugs.
The text was updated successfully, but these errors were encountered:
In order to build associated records for owners which has not been saved
need to get where values to use as default attributes.
But for new record owner uses `ActiveRecord::NullRelation` which
override `where_values_hash` to return empty hash stub.
`where_values_hash` is not used to invoke any sql query, but good to
build others chains (even will be never executed) like:
```ruby
post = Post.new
admin_comment = post.admin_comments.build
assert_equal 'Admin', admin_comment.author
```
Closesrails#11376, rails#11676, rails#11675
I've found an issue where
model.has_many_polymorphic_models.where(condtion:value).first_or_initialize
does not passcondition:value
to the initializedpolymorphic_model
, whereasmodel.has_many_models.where(condtion:value).first_or_initialize
passescondition:value
to the initializedhas_many_model
.The workaround is to use
model.has_many_polymorphic_models.find_or_initialize_by(condition:value)
. But the issue of knowing where your polymorphicfirst_or_initialize
calls are leads to confusing "Why is this nil?!" bugs.The text was updated successfully, but these errors were encountered: