Skip to content

Removed where_values_hash from AR::NullRelation - #11496

Merged
rafaelfranca merged 1 commit into
rails:masterfrom
jetthoughts:11376_has_many_assoc_respect_scope_on_build
Sep 29, 2013
Merged

Removed where_values_hash from AR::NullRelation#11496
rafaelfranca merged 1 commit into
rails:masterfrom
jetthoughts:11376_has_many_assoc_respect_scope_on_build

Conversation

@pftg

@pftg pftg commented Jul 18, 2013

Copy link
Copy Markdown
Contributor

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:

  post          = Post.new
  admin_comment = post.admin_comments.build

  assert_equal 'Admin', admin_comment.author

Closes #11376, #11676 and #11675

@pftg

pftg commented Jul 18, 2013

Copy link
Copy Markdown
Contributor Author

/cc @senny, @rafaelfranca, @jonleighton

@nathanvda

Copy link
Copy Markdown

👍 Nice work, thank you!

@pftg

pftg commented Aug 13, 2013

Copy link
Copy Markdown
Contributor Author

Thanks to @beerlington and @Nthalk for their tests and CHANGELOG

@pftg

pftg commented Aug 13, 2013

Copy link
Copy Markdown
Contributor Author

@rafaelfranca may you check this one, thanks in advance.

@jarl-dk

jarl-dk commented Sep 20, 2013

Copy link
Copy Markdown

Could someone please merge this, it seems to resolve more than one bug report.

@Maxim-Filimonov

Copy link
Copy Markdown

Run into the same issue today with Rails 4. Is it gonna be merged for 4.1.0 ?

@leiyangyou

Copy link
Copy Markdown

+1

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
```

Closes rails#11376, rails#11676, rails#11675
@pftg

pftg commented Sep 28, 2013

Copy link
Copy Markdown
Contributor Author

Rebased!

@rafaelfranca

Copy link
Copy Markdown
Member

Merged. Sorry for the delay guys

rafaelfranca added a commit that referenced this pull request Sep 29, 2013
…ct_scope_on_build

Removed where_values_hash from AR::NullRelation
Conflicts:
	activerecord/CHANGELOG.md
@pftg
pftg deleted the 11376_has_many_assoc_respect_scope_on_build branch September 29, 2013 06:38
@jarl-dk

jarl-dk commented Sep 29, 2013

Copy link
Copy Markdown

Thanks... Any plans for a 4.0.1 release?

@nathanvda

Copy link
Copy Markdown

Thanks @rafaelfranca! 👍

@robin850

Copy link
Copy Markdown
Member

@jarl-dk : Yes, the pull request has been backported to the 4-0-stable branch so it will be in 4.0.1 which will be released soon. There is still issues which need to be resolved to get 4.0.1 out unfortunately.

@jarl-dk

jarl-dk commented Oct 1, 2013

Copy link
Copy Markdown

@robin850: I hope this bug (#12417) is one of those that need to be resolved in 4-0-stable.

@robin850

robin850 commented Oct 1, 2013

Copy link
Copy Markdown
Member

@jarl-dk : Most of the time, the issues are put under a "milestone" on this tracker. As you can see, this is under the 4.0.1 milestone so this should be. :-)

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.

[rails4] :has_many with a scope does not build a correct object (if the object was not saved to the db before)

7 participants