Commit Graph

149 Commits

Author SHA1 Message Date
Carlos Antonio da Silva
871914c239 Remove deprecated call to Relation#all 2013-12-05 16:32:00 -02:00
Lauro Caetano
2a517e7291 Fix offset with last.
Closes #7441
2013-12-03 17:09:58 -02:00
Rafael Mendonça França
4a26508366 Make the tests break again
We need to fix this test
2013-12-02 19:45:58 -02:00
Yves Senn
140c0c8881 use complete Relation API and not only Model.all.merge!. 2013-11-09 22:02:46 +01:00
Rafael Mendonça França
5741a8aae5 Mark broken test as pending
This will avoid the broken window effect in our test suite
2013-11-08 14:19:09 -02:00
Yves Senn
abe91cb3bf prevent global timezone state from leaking out of test cases. 2013-10-25 14:40:57 +02:00
Shimpei Makimoto
e2419a451a Raise an exception when model without primary key calls .find_with_ids 2013-10-21 17:07:47 +09:00
Rafael Mendonça França + Kassio Borges
78befcfc28 Add a test case for exists? with multiple values 2013-09-04 20:49:04 -03:00
Xavier Noria
565c367d34 let AR::FinderMethods#exists? return singletons in all cases [closes #11592]
This fixes a regression. The documentation said in its introduction
paragraph that the method returns truthy/falsy, but then below it
was said that if there were no arguments you'd get `true` or `false`.
Also when the argument is exactly `false` a singleton is documented
to be returned.

The method was not returning the singletons so it didn't conform to
those special cases.

The best solution here seems to be to just return singletons in all
cases. This solution is backwards compatible. Also, the contract
has been revised because it has no sense that the predicate varies
that way depending on the input. I bet the previous contract was just
an accident, not something mixed on purpose.

Conflicts:
	activerecord/lib/active_record/relation/finder_methods.rb
	activerecord/test/cases/finder_test.rb
2013-08-19 14:38:20 +02:00
Neeraj Singh
e18e7d9253 remove duplicate method
This method is already present in helper.rb
2013-07-29 07:49:56 +05:30
Ben Woosley
31a43ebc10 Don't allow quote_value to be called without a column
Some adapters require column information to do their job properly.
By enforcing the provision of the column for this internal method
we ensure that those using adapters that require column information
will always get the proper behavior.
2013-07-22 04:49:18 -07:00
Ben Woosley
15d6e4dce7 Fix that #exists? can produce invalid SQL: "SELECT DISTINCT DISTINCT"
The combination of a :uniq => true association and the #distinct call
in #construct_limited_ids_condition combine to create invalid SQL, because
we're explicitly selecting DISTINCT, and also sending #distinct on to AREL,
via the relation#distinct_value.

Rather than build a select distinct clause in #construct_limited_ids_condition,
I set #distinct! and pass just the columns into the select statement.
This requires introducing a #columns_for_distinct method to return the
select columns but not the statement itself.
2013-05-10 16:13:46 +02:00
Godfrey Chan
54122067ac Handle aliased attributes in ActiveRecord::Relation.
When using symbol keys, ActiveRecord will now translate aliased attribute names to the actual column name used in the database:

With the model

  class Topic
    alias_attribute :heading, :title
  end

The call

  Topic.where(heading: 'The First Topic')

should yield the same result as

  Topic.where(title: 'The First Topic')

This also applies to ActiveRecord::Relation::Calculations calls such as `Model.sum(:aliased)` and `Model.pluck(:aliased)`.

This will not work with SQL fragment strings like `Model.sum('DISTINCT aliased')`.

Github #7839

*Godfrey Chan*
2013-05-01 16:36:01 -07:00
Aaron Patterson
7c8caf930d adding test for the symbol refs 2013-04-26 16:46:27 -07:00
Andrew White
2d211c459d Reset the primary key for other tests 2013-04-24 15:07:39 +01:00
Yves Senn
a1bb6c8b06 rename Relation#uniq to Relation#distinct. #uniq still works.
The similarity of `Relation#uniq` to `Array#uniq` is confusing. Since our
Relation API is close to SQL terms I renamed `#uniq` to `#distinct`.

There is no deprecation. `#uniq` and `#uniq!` are aliases and will continue
to work. I also updated the documentation to promote the use of `#distinct`.
2013-03-15 14:15:47 +01:00
Guillermo Iguaran
fa987cb8ec Reverting 16f6f25 (Change behaviour with empty array in where clause) 2013-02-08 14:22:10 -05:00
robertomiranda
16f6f2592e Change behaviour with empty array in where clause 2013-02-08 06:37:30 -05:00
Aaron Patterson
44930b2def CVE-2012-5664 options hashes should only be extracted if there are extra parameters
Conflicts:
	activerecord/lib/active_record/dynamic_matchers.rb
2013-01-02 13:44:06 -08:00
Carlos Antonio da Silva
9ad8d670ec Assert the query result instead of checking for nothing raised
Nothing should be raised anyway 😄

Thanks @spastorino ❤️
https://github.com/rails/rails/pull/8202/files#r2112067
2012-11-13 14:54:47 -02:00
Nikita Afanasenko
8424d0dda3 Regression test for #7238 2012-11-13 18:39:07 +04:00
Ernie Miller
4f107da4ff Raise MissingAttributeError on query methods
When calling a query method on an attribute that was not selected by
an ActiveRecord query, an ActiveModel::MissingAttributeError is not
raised. Instead, a nil value is returned, which will return false once
cast to boolean.

This is undesirable, as we should not give the impression that we know
the attribute's boolean value when we haven't loaded the attribute's
(possibly) non-boolean value from the database.

This issue is present on versions going back as far as 2.3, at least.
2012-09-08 17:40:01 -04:00
Jon Leighton
55b24888bb Remove ActiveRecord::Base.to_a
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.
2012-08-03 11:51:52 +01:00
Rafael Mendonça França
f4d818d51e Revert "Removing composed_of from ActiveRecord."
This reverts commit 14fc8b34521f8354a17e50cd11fa3f809e423592.

Reason: we need to discuss a better path from this removal.

Conflicts:
	activerecord/lib/active_record/reflection.rb
	activerecord/test/cases/base_test.rb
	activerecord/test/models/developer.rb
2012-07-27 19:25:14 -03:00
Jon Leighton
b658cf1198 Deprecate ActiveRecord::Base.scoped.
It doesn't serve much purpose now that ActiveRecord::Base.all returns a
Relation.

The code is moved to active_record_deprecated_finders.
2012-07-27 17:27:47 +01:00
Jon Leighton
6a81ccd69d ActiveRecord::Base.all returns a Relation.
Previously it returned an Array.

If you want an array, call e.g. `Post.to_a` rather than `Post.all`. This
is more explicit.

In most cases this should not break existing code, since
Relations use method_missing to delegate unknown methods to #to_a
anyway.
2012-07-27 13:34:12 +01:00
Egor Lynko
359592bba6 exists?(false) returns false
`FinderMethods#exists?` finder method now returns *false* with the *false* argument
2012-06-25 18:30:15 +03:00
Maximilian Schneider
f984b8152f made dynamic finders alias_attribute aware
previously dynamic finders only worked in combination with the actual
column name and not its alias defined with #alias_attribute
2012-06-22 16:44:01 +02:00
Steve Klabnik
14fc8b3452 Removing composed_of from ActiveRecord.
This feature adds a lot of complication to ActiveRecord for dubious
value. Let's talk about what it does currently:

class Customer < ActiveRecord::Base
  composed_of :balance, :class_name => "Money", :mapping => %w(balance amount)
end

Instead, you can do something like this:

    def balance
      @balance ||= Money.new(value, currency)
    end

    def balance=(balance)
      self[:value] = balance.value
      self[:currency] = balance.currency
      @balance = balance
    end

Since that's fairly easy code to write, and doesn't need anything
extra from the framework, if you use composed_of today, you'll
have to add accessors/mutators like that.

Closes #1436
Closes #2084
Closes #3807
2012-06-18 14:53:03 -04:00
Yasuo Honda
a0363e2ca6 Address ORA-00911 errors because of the heading underscore. 2012-06-11 11:41:07 +09:00
Ben Woosley
340a93f502 Fix that #exists? raises ThrowResult when called with an empty limited
reflection.

ActiveRecord::FinderMethods#construct_limited_ids_condition will raise
ThrowResult if the limited reflection comes back empty. The other callers
of #construct_limited_ids_condition handle this exception (more specifically,
the callers of construct_relation_for*), but #exists? didn't until now.
2012-06-10 17:51:17 -07:00
Rafael Mendonça França
6cc5e9aa81 Add test to column alias in exists? SQL.
This behavior was added in be4ecdcc87984e9421ff5d5c90d33f475e0fbc01.

Closes #1139.

Fixes #2553, #1141, #1623 and #2062.
2012-06-10 16:57:03 -03:00
Akira Matsuda
edee2c7b3b stop to_sing method names
Module#methods are Symbols in Ruby >= 1.9
2012-06-06 19:33:38 +09:00
Jon Leighton
62c6ac2f8d quarantine more deprecated stuff 2012-05-18 15:04:36 +01:00
Jon Leighton
ee16feae4a quarantine deprecated tests 2012-05-18 14:46:54 +01:00
Andrew White
fa21b73ebb Return false for exists? with new records - fixes #6199. 2012-05-10 23:16:40 +01:00
Marcelo Silveira
56bf1f7455 Use take instead of first to avoid unwanted implicit ordering (fixes #6147) 2012-05-05 12:10:52 -03:00
Marcelo Silveira
1379375f93 Introducing take as a replacement to the old behavior of first 2012-05-02 21:25:40 -03:00
Marcelo Silveira
07e5301e69 Made first finder consistent among database engines by adding a
default order clause (fixes #5103)
2012-05-02 21:25:24 -03:00
Jon Leighton
3981a687f9 remove deprecated calls 2012-04-27 14:28:36 +01:00
Jon Leighton
20ea8df6b5 more deprecations manually fixed 2012-04-27 13:11:13 +01:00
Jon Leighton
0ed05b0e73 find and replace deprecated keys 2012-04-27 12:37:21 +01:00
Jon Leighton
df6f971e3a %s/find(:\(first\|last\|all\), \([^()]*\))/scoped(\2).\1/gcI amongst other things 2012-04-27 11:42:50 +01:00
Jon Leighton
75f03eca75 remove calls to find(:first), find(:last) and find(:all) 2012-04-26 18:32:55 +01:00
Jon Leighton
b30996307d remove deprecate #all usage 2012-04-26 18:04:41 +01:00
Jon Leighton
759d302db8 remove deprecate #calculate calls 2012-04-26 18:04:41 +01:00
Jon Leighton
1606bee64a fix #scoped deprecations 2012-04-26 13:29:48 +01:00
Jon Leighton
40a711ce29 remove tests for #with_scope (it's now deprecated) 2012-04-25 17:52:28 +01:00
Jon Leighton
1ad138cf4b fix tests 2012-04-13 18:26:19 +01:00
Andrew White
eee32af45e Add dynamic find_or_create_by_{attribute}! method. 2012-03-12 14:16:19 +00:00