Commit Graph

319 Commits

Author SHA1 Message Date
Neeraj Singh
91fec0d24d order should always be concatenated.
order that is declared first has highest priority in all cases.

Here are some examples.

Car.order('name desc').find(:first, :order => 'id').name

Car.named_scope_with_order.named_scope_with_another_order

Car.order('id DESC').scoping do
  Car.find(:first, :order => 'id asc')
end

No special treatment to with_scope or scoping.

Also note that if default_scope declares an order then the order
declared in default_scope has the highest priority unless
with_exclusive_scope is used.

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2010-09-05 08:13:42 -03:00
Santiago Pastorino
b451de0d6d Deletes trailing whitespaces (over text files only find * -type f -exec sed 's/[ \t]*$//' -i {} \;) 2010-08-14 04:12:33 -03:00
Robert Pankowecki
f8b53f35b9 test and fix collection_singular_ids= with string primary keys [#5125 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-08-02 16:41:20 +02:00
Neeraj Singh
992711a86b update_attribute should not update readonly attributes
[#5106 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-07-21 14:55:57 +02:00
Will St. Clair + Neeraj Singh
b520d602ff string IDs are now quoted correctly [#5064 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-07-13 08:14:52 +02:00
Neeraj Singh
1e53404fe9 reset_counter should work with non-traditional belongs_to and polymorphic belongs_to
[#4984 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-07-08 23:24:12 +02:00
Santiago Pastorino
a2513aea07 Test for concatenated orders added
[#4972]

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-06-26 00:59:11 +02:00
Andrew White
8ec085bf18 Support fixtures for namespaced models [#2965 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-04-25 16:04:38 +02:00
Aaron Patterson
cd6578f6a1 fixing invalid yaml [#4424 state:resolved]
Signed-off-by: wycats <wycats@gmail.com>
2010-04-17 00:14:23 -04:00
Andrew White
9cea9bc7f0 Refactor compute_type to handle situations where the correct class is already loaded
Signed-off-by: wycats <wycats@gmail.com>
2010-04-12 21:31:20 -07:00
George Ogata
81ca0cf2b0 Add inverse polymorphic association support. [#3520 state:resolved]
Signed-off-by: Eloy Duran <eloy.de.enige@gmail.com>
2009-12-28 15:12:13 +01:00
Jeremy Kemper
78790e47b8 Revert "Revert "Assert primary key does not exist in habtm when the association is defined, instead of doing that everytime a record is inserted.""
This reverts commit 2b82708b0efb3a3458e8177beab58f0c585788ae.

[#3128 state:resolved]

Conflicts:

	activerecord/lib/active_record/associations.rb
	activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
2009-11-23 10:42:32 -08:00
Graeme Porteous
c01be9de32 Fix has_one with foreign_key and primary_key association bug which caused the associated object being lost when saving the owner. [#1756 state:resolved]
Mixed in a bit from patch by ransom-briggs. [#2813 state:resolved]

Signed-off-by: Eloy Duran <eloy.de.enige@gmail.com>
2009-09-12 16:03:32 +02:00
Jeremy Kemper
3b6a9a020e Revert "Assert primary key does not exist in habtm when the association is defined, instead of doing that everytime a record is inserted."
Test failures on PostgreSQL.

[#3128 state:open]

This reverts commit da636809daca9c338200811d3590e446f57c8e81.
2009-09-02 13:55:47 -07:00
José Valim
da636809da Assert primary key does not exist in habtm when the association is defined, instead of doing that everytime a record is inserted.
[#3128 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2009-09-01 10:15:23 -07:00
Gabe da Silveira
7e3364ac46 Fix that counter_cache breaks with has_many :dependent => :nullify.
[#1196 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2009-08-09 21:18:16 -07:00
Pratik Naik
45e6f19925 Revert "Revert "Generate proper :counter_sql from :finder_sql when there is a newline character immediately following 'SELECT' [#2118 state:resolved]""
This reverts commit 80f1f863cd0f9cba89079511282de5710a2e1832.

The feature doesn't work on Postgres, so don't test it on Postgres.
Also, Postgres compatibility is irrelevant to the ticket/patch in question.
2009-07-01 00:02:00 +01:00
Yehuda Katz + Carl Lerche
80f1f863cd Revert "Generate proper :counter_sql from :finder_sql when there is a newline character immediately following 'SELECT' [#2118 state:resolved]"
This reverts commit 4851ca9e13a4317342df02ae25b1929340523f7a.

The tests do not pass for postgresql.
2009-06-22 12:04:02 -07:00
Patrick Joyce
4851ca9e13 Generate proper :counter_sql from :finder_sql when there is a newline character immediately following 'SELECT' [#2118 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
2009-06-21 22:07:23 +01:00
Benjamin Floering
27de7f150b Fixed limited eager loading associations with numbers in the name [#2668 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
2009-05-18 13:56:17 +02:00
Jeremy Kemper
ddbeb15a5e Revert "Fixed bug with polymorphic has_one :as pointing to an STI record"
[#2594 state:open]

This reverts commit 99c103be1165da9c8299bc0977188ecf167e06a5.
2009-05-11 12:20:54 -07:00
Murray Steele
ccea98389a Providing support for :inverse_of as an option to associations.
You can now add an :inverse_of option to has_one, has_many and belongs_to associations.  This is best described with an example:

class Man < ActiveRecord::Base
  has_one :face, :inverse_of => :man
end

class Face < ActiveRecord::Base
  belongs_to :man, :inverse_of => :face
end

m = Man.first
f = m.face

Without :inverse_of m and f.man would be different instances of the same object (f.man being pulled from the database again).  With these new :inverse_of options m and f.man are the same in memory instance.

Currently :inverse_of supports has_one and has_many (but not the :through variants) associations.  It also supplies inverse support for belongs_to associations where the inverse is a has_one and it's not a polymorphic.

Signed-off-by: Murray Steele <muz@h-lame.com>
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2009-05-04 15:27:39 -07:00
Ruy Asan
99c103be11 Fixed bug with polymorphic has_one :as pointing to an STI record
[#2594 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2009-05-01 14:47:56 -07:00
Jim Remsik and Tim Pope
1e6c50e21b Ensure has_many :through works with changed primary keys [#736 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
2009-03-09 13:43:28 +00:00
Frederick Cheung
5cebe69e74 Preload uses exclusive scope [#643 state:resolved]
With self referential associations, the scope for the the top level should not affect fetching of associations, for example
when doing

Person.male.find :all, :include => :friends

we should load all of the friends for each male, not just the male friends.
2008-12-26 18:25:55 +00:00
Matt Jones
a9422cc1db Fix preloading of has_one :through associations on belongs_to [#1507 state:resolved]
Signed-off-by: Frederick Cheung <frederick.cheung@gmail.com>
2008-12-18 19:19:36 +00:00
Matt Jones
d3fd997109 fix assignment to has_one :through associations.
Signed-off-by: Michael Koziarski <michael@koziarski.com>
2008-11-15 18:20:39 +01:00
Rob Anderton
2cee51d5c1 Added :constructor and :converter options to composed_of and deprecated the conversion block
Signed-off-by: Michael Koziarski <michael@koziarski.com>
2008-09-10 18:28:47 +02:00
Andre Arko
3351d29970 Add has_many :primary_key option to allow setting the primary key on a has many association
Signed-off-by: Michael Koziarski <michael@koziarski.com>
2008-07-06 20:25:10 +02:00
David Heinemeier Hansson
ab4d455d6d Added missing files 2008-05-01 15:03:16 -05:00
Frederick Cheung
44d2142352 Ensure table names are quoted by the association preloading code.
[#45 state:resolved]

Signed-off-by: Michael Koziarski <michael@koziarski.com>
2008-04-26 12:14:50 +12:00
Rick Olson
081ddb6f24 Merge the has_finder gem, renamed as 'named_scope'. Closes #11404 [nkallen]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9084 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-03-24 02:50:02 +00:00
Jeremy Kemper
5c1be2812d has_one :through supports :source_type. Fix up some tests. References #4756.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9075 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-03-22 02:20:37 +00:00
Rick Olson
273b21faa9 Add has_one :through support, finally. Closes #4756 [thechrisoshow]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9067 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-03-21 18:09:03 +00:00
Jeremy Kemper
5dee6ce9e0 Fix that batched :include would pull in duplicate records in some cases. Closes #11215 [Catfish]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8942 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-02-28 20:42:01 +00:00
Jeremy Kemper
558c5ff251 Fix preloading nil polymorphic belongs_to. Closes #11218 [matrix9180]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8933 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-02-27 22:41:35 +00:00
Michael Koziarski
f2546164d6 Make dynamic finders respect the :include on HasManyThrough associations. Closes #10998. [cpytel]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8890 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-02-18 00:14:54 +00:00
Jeremy Kemper
b1ea27630d Fix has_many :through a polymorphic has_many. Closes #10529 [Aleksey Kondratenko]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8776 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-02-02 03:27:31 +00:00
Jeremy Kemper
be827f9348 Fixed preloading belongs_to associations which reference a custom foreign key. References #9640.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8762 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-01-31 07:50:15 +00:00
Michael Koziarski
c48f744400 Make sure that belongs_to counter decrements when assigning nil Closes #10804 [jeanmartin]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8735 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-01-26 06:23:03 +00:00
Jeremy Kemper
32b36b8936 Add missing author_addresses.yml fixture. Closes #10592.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8682 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-01-21 17:21:12 +00:00
Jeremy Kemper
39814fcce0 Merge branch 'ar-test-cleanup' of git://git.geeksomnia.com/rails
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8681 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-01-21 17:20:51 +00:00
Jeremy Kemper
16b129a68c belongs_to supports :dependent => :destroy and :delete. Closes #10592.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8675 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-01-19 05:30:42 +00:00
Jeremy Kemper
105a27f39e move schema
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8659 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-01-18 07:29:00 +00:00
Jeremy Kemper
e899a83a85 move migrations
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8658 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-01-18 07:28:07 +00:00
Jeremy Kemper
43b81d01d0 move assets and models
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8657 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-01-18 07:27:03 +00:00
Jeremy Kemper
8f7fa55e8d Fixtures: removed support for the ancient pre-YAML file format. Closes #10736.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8594 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-01-08 03:54:40 +00:00
Jeremy Kemper
ebe3a0d532 More thoroughly quote table names. Exposes some issues with sqlite2 adapter. Closes #10698.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8571 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-01-05 14:58:28 +00:00
Jeremy Kemper
f6379bfe15 Eager belongs_to :include infers the foreign key from the association name rather than the class name. Closes #10517.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8456 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2007-12-21 01:49:01 +00:00
Rick Olson
66e97c34c1 Ensure that the :uniq option for has_many :through associations retains the order. #10463 [remvee]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8376 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2007-12-11 20:08:30 +00:00