Carlos Antonio da Silva
a739340d3c
Ensure ordering to make the test pass with postgresql
2012-11-18 16:27:50 -02:00
Dieter Komendera
22ed92dbae
Add test to ensure preloading works as expected with "select" and "includes".
...
This didn't work in rails 3.1. See #2303 for more information and original pull request.
2012-11-18 13:17:11 +01:00
Juanjo Bazán
35ca953a27
loaded relations cannot be mutated by extending!
2012-10-28 22:17:34 +01:00
Jon Leighton
0096f53b25
nodoc the first_or_create methods and document alternatives
2012-10-19 15:56:18 +01:00
Jon Leighton
eb72e62c30
Add Relation#find_or_create_by and friends
...
This is similar to #first_or_create, but slightly different and a nicer
API. See the CHANGELOG/docs in the commit.
Fixes #7853
2012-10-19 13:18:47 +01:00
Tima Maslyuchenko
633ea6a826
learn ActiveRecord::QueryMethods#order work with hash arguments
2012-10-12 17:57:24 +03:00
Yves Senn
626f7df626
remove duplicated require statements in AR test cases
2012-10-09 21:33:54 +02:00
Isaac Sanders
7bf9db529e
Model.select takes a variable list of arguments.
...
This is a cleaner version of #6916 .
Closes #3165 .
2012-08-23 13:51:10 -05:00
Ernie Miller
bf80522be4
Fix "last equality wins" logic in relation merge
...
This is a real fix (as compared to the band-aid in b127d86c), which uses
the recently-added equality methods for ARel nodes. It has the side
benefit of simplifying the merge code a bit.
2012-08-19 08:06:31 -04:00
Ernie Miller
b127d86c18
Fix merge error when Equality LHS is non-attribute
...
This is at best a band-aid for a more proper fix, since it won't truly
handle the removal of the previous equality condition of these other
nodes. I'm planning to put in some work on ARel toward supporting that
goal.
Related: rails/arel#130 , ernie/squeel#153 , ernie/squeel#156
2012-08-17 11:31:23 -04:00
Carlos Antonio da Silva
cf232e37ad
Merge pull request #7133 from roshats/fix_update_all_with_blank_argument
...
Change Relation#update_all with blank argument to raise an ArgumentError
instead of trying an update with empty fields.
2012-08-15 08:45:15 -07:00
Roman Shatsov
f28096476d
raise ArgumentError if list of attributes to change is empty in update_all
2012-08-14 21:04:48 +03: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
Jon Leighton
437851ea02
Add Relation#load
...
This method explicitly loads the records and then returns `self`.
Rather than deciding between "do I want an array or a relation?",
most people are actually asking themselves "do I want to eager load
or lazy load?" Therefore, this method provides a way to explicitly
eager-load without having to switch from a `Relation` to an array.
Example:
@posts = Post.where(published: true).load
2012-08-01 21:59:46 +01:00
Bogdan Gusiev
92641efeec
AR::Relation#order: make new order prepend old one
...
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.
2012-07-31 10:24:18 +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
Jon Leighton
4b4a85515b
support relations created with a table alias
2012-07-13 11:44:45 +01:00
Jon Leighton
c433adffa2
Relation#inspect handles doesn't perform a new query on an already-loaded relation
2012-07-07 10:07:28 +01:00
Damien Mathieu
7d0053e6a7
Limit the number of records in Relation#inspect
...
While it's interesting to have the results array, it can make a console or a webpage freeze if there are a lot of them.
So this limits the number of records displayed in #inspect to 10 and tells how much were effectively found.
2012-07-06 20:04:38 +02:00
Jon Leighton
07314e64fd
Show the records in Relation#inspect
...
The reason for removing the previous implementation of `#inspect` was
that it hid from you that you were dealing with a `Relation` rather than
an `Array`.
But it is still useful to be able to see the records, particularly if you're
writing something like the following in tests:
assert_equal [foo], Post.where(:bar)
If the assertion fails, you want to see what records were actually
loaded.
So this implementation makes it clear that you've got a `Relation`, but
also shows your records.
2012-07-06 10:39:46 +01:00
Jon Leighton
70d3625760
disallow mutating a relation once loaded
2012-06-22 10:29:49 +01:00
Akira Matsuda
37a4dd5ccf
a test case that ensures AR::Relation#merge can merge associations
2012-06-03 13:28:01 +09:00
Akira Matsuda
212a74d8b7
modulize AR::NullRelation
...
now we can invoke previously added scope extension methods
2012-06-01 14:46:13 +09:00
Ivan Kukobko
45d059b401
fixed typo in word finiding
2012-05-20 22:11:32 +03: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
Radoslav Stankov
64872d1e34
Relation#from to accept other Relation objects
...
Record.from("(#{sub_query.to_sql})") -> Record.from(sub_query)
Record.from("(#{sub_query.to_sql}) a") -> Record.from(sub_query, :a)
2012-05-17 02:36:13 +03: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
Francesco Rodriguez
2f681254ee
delete_all raise an error if a limit is provided - fixes #4979
2012-04-30 10:49:20 -05: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
b30996307d
remove deprecate #all usage
2012-04-26 18:04:41 +01:00
Jon Leighton
e1a83690da
remove deprecated scope stuff
2012-04-26 13:29:47 +01:00
Jon Leighton
40a711ce29
remove tests for #with_scope (it's now deprecated)
2012-04-25 17:52:28 +01:00
Juanjo Bazán
1a20683f09
Override AR::Relation methods in NullRelation.
...
So a NullRelation (Relation#none) is chainable with database methods.
2012-04-11 15:24:23 +02:00
Jon Leighton
13b3c77e39
Add Relation#find_by and Relation#find_by!
2012-03-30 12:52:29 +01:00
Ruben Davila
9679d4015e
Fix typo in ActiveRecord::Relation#blank? test
2012-03-17 12:22:54 -05:00
Rafael Mendonça França
404d785d29
Fix ActiveRecord::Relation#blank? tests
2012-03-16 17:05:35 -03:00
Thiago Almeida
964ed6e802
test relation presence fix
2012-03-16 11:30:24 -03:00
Thiago Almeida
4498f93e68
tests for Relation .present? and .blank? are check cases and shouldn't force sql-count
2012-03-16 11:04:24 -03:00
Carlos Antonio da Silva
a8dd21d8b4
Remove IdentityMap
2012-03-13 20:08:54 -03:00
Andrew White
eee32af45e
Add dynamic find_or_create_by_{attribute}! method.
2012-03-12 14:16:19 +00:00
Vishnu Atrai
a62088a4da
fix build #5001 reply model required in relations_test
2012-02-12 13:35:50 +05:30
Karunakar (Ruby)
7381596ea3
removed unuseful require for reply as we are not using require model
2012-02-11 18:54:20 +05:30
Juanjo Bazán
8270e4a8ce
Added none
query method to return zero records.
...
And added NullRelation class implementing the null object pattern for the `Relation` class.
2012-01-31 19:50:09 +01:00
Jon Leighton
a2dab46cae
Deprecate inferred JOINs with includes + SQL snippets.
...
See the CHANGELOG for details.
Fixes #950 .
2012-01-16 21:32:12 +00:00
Jon Leighton
46ea4442f3
infer references from Relation#order
2012-01-16 21:17:18 +00:00
Jon Leighton
a84a20e1cd
store references as a string
2012-01-16 21:17:18 +00:00