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

Removed where_values_hash from AR::NullRelation #11496

Conversation

pftg
Copy link
Contributor

@pftg pftg commented Jul 18, 2013

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
Copy link
Contributor Author

pftg commented Jul 18, 2013

/cc @senny, @rafaelfranca, @jonleighton

@nathanvda
Copy link

👍 Nice work, thank you!

@pftg
Copy link
Contributor Author

pftg commented Aug 13, 2013

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

@pftg
Copy link
Contributor Author

pftg commented Aug 13, 2013

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

@jarl-dk
Copy link

jarl-dk commented Sep 20, 2013

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

@Maxim-Filimonov
Copy link

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

@leiyangyou
Copy link

+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
Copy link
Contributor Author

pftg commented Sep 28, 2013

Rebased!

@rafaelfranca
Copy link
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
Copy link

jarl-dk commented Sep 29, 2013

Thanks... Any plans for a 4.0.1 release?

@nathanvda
Copy link

Thanks @rafaelfranca! 👍

@robin850
Copy link
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
Copy link

jarl-dk commented Oct 1, 2013

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

@robin850
Copy link
Member

robin850 commented Oct 1, 2013

@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