| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
| |
This test does not belong to has many associations test.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Consider this scenario:
if params[:foo]
conditions = { foo: true }
end
foos = Foo.where(conditions).order(:id)
When params[:foo] is nil, this would call:
foos = Foo.where(nil).order(:id)
In this scenario, we want Foo.where(conditions) to be the same as calling
Foo.all, otherwise we'd get a "NoMethodError order for WhereChain".
Related to #8332.
|
|\
| |
| |
| |
| |
| |
| |
| | |
Relation.where with no args can be chained with not, like, and not_like
Conflicts:
activerecord/CHANGELOG.md
activerecord/lib/active_record/relation/query_methods.rb
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
examples:
Model.where.not field: nil
#=> "SELECT * FROM models WHERE field IS NOT NULL
Model.where.like name: 'Jeremy%'
#=> "SELECT * FROM models WHERE name LIKE 'Jeremy%'
this feature was originally suggested by Jeremy Kemper https://github.com/rails/rails/pull/5950#issuecomment-5591330
Closes #5950
|
| |
| |
| |
| | |
Closes #3313
|
| | |
|
| | |
|
|/
|
|
|
|
|
|
| |
Allows you to do BaseClass.new(:type => "SubClass") as well as
parent.children.build(:type => "SubClass") or parent.build_child
to initialize an STI subclass. Ensures that the class name is a
valid class and that it is in the ancestors of the super class
that the association is expecting.
|
| |
|
|\
| |
| |
| |
| |
| |
| | |
prevent mass assignment of polymorphic type when using `build`
Conflicts:
activerecord/CHANGELOG.md
|
| |
| |
| |
| | |
Closes #8265
|
|/
|
|
|
|
|
| |
To perform a sum calculation over the array of elements, use to_a.sum(&block).
Please check the discussion in f9cb645dfcb5cc89f59d2f8b58a019486c828c73
for more context.
|
|
|
|
| |
See issue #7950.
|
| |
|
| |
|
|\
| |
| | |
:counter_cache option for to support custom named counter caches
|
| | |
|
| |
| |
| |
| |
| |
| |
| | |
So that the scope may be a NullRelation and return a result without
executing a query.
Fixes #7928
|
| |
| |
| |
| |
| |
| |
| | |
Fixes #8102.
I couldn't find a nicer way to deal with this than delegate the call to
#scope, which will be a NullRelation when we want it to be.
|
|/
|
|
|
|
|
|
|
|
| |
null relations
For example, the following should not run any query on the database:
Post.new.comments.where(body: 'omg').to_a # => []
Fixes #5215.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
When calling first(n) or last(n) in a collection, Active Record was
improperly trying to set the inverse of instance in case that option
existed. This change was introduced by
fdf4eae506fa9895e831f569bed3c4aa6a999a22.
In such cases we don't need to do that "manually", since the way
collection will be loaded will already handle that, so we just skip
setting the inverse association when any argument is given to
first(n)/last(n).
The test included ensures that these scenarios will have the inverse of
instance set properly.
Fixes #8087, Closes #8094.
Squashed cherry-pick from d37d40b and c368b66.
Conflicts:
activerecord/CHANGELOG.md
activerecord/lib/active_record/associations/collection_association.rb
|
|\
| |
| | |
remove duplicated require statements in AR test cases
|
| | |
|
|/
|
|
|
|
|
|
|
|
|
|
|
|
| |
If you create a new record via a collection association proxy that has
not loaded its target, and which selects additional attributes through
the association, then when the proxy loads its target, it will
inadvertently trigger an ActiveModel::MissingAttributeError during
attribute writing when CollectionAssociation#merge_target_lists attempts
to do its thing, since the newly loaded records will possess attributes
the created record does not.
This error also raises a bogus/confusing deprecation warning when
accessing the association in Rails 3.2.x, so cherry-pick would be
appreciated!
|
|
|
|
|
|
|
|
|
|
|
| |
This reverts commit abf8de85519141496a6773310964ec03f6106f3f.
We should take a deeper look to those cases flat_map doesn't do deep
flattening.
irb(main):002:0> [[[1,3], [1,2]]].map{|i| i}.flatten
=> [1, 3, 1, 2]
irb(main):003:0> [[[1,3], [1,2]]].flat_map{|i| i}
=> [[1, 3], [1, 2]]
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Patches `CollectionAssociation#count` to return 0 without querying
if the parent record is new. Consider the following code:
class Account
has_many :dossiers
end
class Dossier
belongs_to :account
end
a = Account.new
a.dossiers.build
# before patch
a.dossiers.count
# SELECT COUNT(*) FROM "dossiers" WHERE "dossiers"."account_id" IS NULL
# => 0
# after
a.dosiers.count # fires without sql query
# => 0
Fixes #1856.
|
|
|
|
| |
65843e1acc0c8d285ff79f8c9c49d4d1215440be
|
|\
| |
| | |
Integrate strong_parameters in Rails 4
|
| | |
|
| | |
|
|\ \
| | |
| | | |
Fix collection= on hm:t join models when unsaved
|
| | |
| | |
| | |
| | |
| | |
| | | |
If assigning to a has_many :through collection against an unsaved
object using the collection=[<array_of_items>] syntax, the join models
were not properly created, previously.
|
| |/
|/| |
|
|/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The COUNT clause of a finder_sql relationship is being rewritten from
COUNT(*) to COUNT(table_name.*). This does not appear to be valid syntax
in MySQL:
```
mysql> SELECT COUNT( table_name.* ) FROM `table_name`;
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near '* ) FROM `table_name`' at line 1
```
This fixes the bug, as well as adding tests so we don't re-introduce
it in the future.
Fixes #3956.
|
|\
| |
| | |
Fix eagerly loading associations without primary keys
|
| | |
|
| | |
|
| |
| |
| |
| | |
scope conditions
|
| | |
|
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Method compilation provides better performance and I think the code
comes out cleaner as well.
A knock on effect is that methods that get redefined produce warnings. I
think this is a good thing. I had to deal with a bunch of warnings
coming from our tests, though.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
It's not really a good idea to have this as a global config option. We
should allow people to specify the behaviour per association.
There will now be two new values:
* :dependent => :restrict_with_exception implements the current
behaviour of :restrict. :restrict itself is deprecated in favour of
:restrict_with_exception.
* :dependent => :restrict_with_error implements the new behaviour - it
adds an error to the owner if there are dependent records present
See #4727 for the original discussion of this.
|
| | |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
by Active Support)
Selecting which key extensions to include in active_support/rails
made apparent the systematic usage of Object#in? in the code base.
After some discussion in
https://github.com/rails/rails/commit/5ea6b0df9a36d033f21b52049426257a4637028d
we decided to remove it and use plain Ruby, which seems enough
for this particular idiom.
In this commit the refactor has been made case by case. Sometimes
include? is the natural alternative, others a simple || is the
way you actually spell the condition in your head, others a case
statement seems more appropriate. I have chosen the one I liked
the most in each case.
|
| |
| |
| |
| |
| | |
On reflection, it seems like a bit of a weird method to have on
ActiveRecord::Base, and it shouldn't be needed most of the time anyway.
|
| | |
|
| | |
|
| | |
|
| |
| |
| |
| |
| |
| |
| |
| |
| | |
This reverts commit 3803fcce26b837c0117f7d278b83c366dc4ed370.
Conflicts:
activerecord/CHANGELOG.md
It will be deprecated only in 4.0, and removed properly in 4.1.
|
| |
| |
| |
| |
| |
| |
| | |
User.order("name asc").order("created_at desc")
# SELECT * FROM users ORDER BY created_at desc, name asc
This also affects order defined in `default_scope` or any kind of associations.
|