aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/collection_association.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* Count returns 0 without querying if parent is not savedFrancesco Rodriguez2012-10-031-0/+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.
* Remove mass_assignment_options from ActiveRecordGuillermo Iguaran2012-09-161-10/+10
|
* Remove debug code :bomb:Rafael Mendonça França2012-09-161-1/+0
|
* Don't preserve SELECT columns on COUNTSteve Klabnik2012-09-161-1/+2
| | | | | | | | | | | | | | | | | | 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.
* Use inversed parent for first and last child of has_many associationbrainopia2012-08-181-1/+1
|
* Changing AR:CollectionAssociation#empty? to use #exists?beerlington2012-08-051-3/+11
| | | | | COUNT(*) queries can be slow in PostgreSQL, #exists? avoids this by selecting a single record.
* s/scoped/scope/Jon Leighton2012-08-011-10/+10
|
* Deprecate :finder_sql, :counter_sql, :insert_sql, :delete_sql.Jon Leighton2012-08-011-1/+1
|
* Revert "Remove :finder_sql, :counter_sql, :insert_sql, :delete_sql."Jon Leighton2012-08-011-16/+69
| | | | | | | | | This reverts commit 3803fcce26b837c0117f7d278b83c366dc4ed370. Conflicts: activerecord/CHANGELOG.md It will be deprecated only in 4.0, and removed properly in 4.1.
* we don't need this argJon Leighton2012-07-201-2/+2
|
* Remove :finder_sql, :counter_sql, :insert_sql, :delete_sql.Jon Leighton2012-07-201-69/+16
|
* Remove obsolete line.Jon Leighton2012-07-201-1/+0
| | | | | | | | This code is broken (it should say association_scope.uniq_value rather than options[:uniq]) but the tests still pass. I think it is designed to uniq-ify associations using finder_sql. However, I am about to remove that anyway.
* Represent association scope options as AR::Relations insternally.Jon Leighton2012-07-131-5/+5
|
* Set the hash value directly instead of using merge!Carlos Antonio da Silva2012-06-211-1/+1
|
* Remove unneeded code since pluck is respecting joins nowRafael Mendonça França2012-06-191-12/+1
|
* Add support for CollectionAssociation#delete by Fixnum or StringFrancesco Rodriguez2012-05-281-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | I found the next issue between CollectionAssociation `delete` and `destroy`. class Person < ActiveRecord::Base has_many :pets end person.pets.destroy(1) # => OK, returns the destroyed object person.pets.destroy("2") # => OK, returns the destroyed object person.pets.delete(1) # => ActiveRecord::AssociationTypeMismatch person.pets.delete("2") # => ActiveRecord::AssociationTypeMismatch Adding support for deleting with a fixnum or string like `destroy` method.
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-05-191-10/+24
|\
| * move docs from CollectionAssociation to CollectionProxyFrancesco Rodriguez2012-05-181-113/+1
| |
| * remove incorrect example of CollectionAssociation#empty?Francesco Rodriguez2012-05-181-17/+0
| |
| * add docs to CollectionAssociation#empty?Francesco Rodriguez2012-05-181-3/+32
| |
| * add docs to CollectionAssociation#any?Francesco Rodriguez2012-05-181-0/+30
| |
| * add examples to CollectionAssociation#concatFrancesco Rodriguez2012-05-181-3/+14
| |
| * fix CollectionAssociation docsFrancesco Rodriguez2012-05-171-1/+1
| |
| * add example to CollectionAssociation#destroy_allFrancesco Rodriguez2012-05-171-3/+14
| |
| * add more explanation to CollectionAssociation docsFrancesco Rodriguez2012-05-171-0/+4
| |
| * add CollectionAssociation hierarchyFrancesco Rodriguez2012-05-171-2/+7
| |
| * add docs to CollectionAssociation#many?Francesco Rodriguez2012-05-171-1/+34
| |
| * fix CollectionAssociation#replace docsFrancesco Rodriguez2012-05-171-3/+3
| |
| * Add docs to CollectionAssociation#replaceFrancesco Rodriguez2012-05-171-3/+23
| |
* | Ensure that CollectionAssociation#replace returns proper targetPiotr Sarnacki2012-05-191-1/+1
| | | | | | | | | | | | | | | | The fix commited in e2a070c was returning the `new_target`, as a try to return whatever user replaced association with. The problem is, the resulting association target may be ordered differently. In such case we want to return the target that will be later used for that association.
* | no longer need #delete_all_on_destroyJon Leighton2012-05-181-7/+0
| |
* | Perf: Don't load the association for #delete_all.Jon Leighton2012-05-181-2/+12
|/ | | | Bug #6289
* Merge pull request #5453 from ↵Aaron Patterson2012-05-161-2/+6
|\ | | | | | | | | JonRowe/patch_uniq_has_and_belongs_to_many_when_already_loaded When Active Record has already loaded a unique association `.size` returns the wrong number.
| * when using a preloaded array and the uniq flag is set then return the size ↵Jon Rowe2012-03-151-2/+6
| | | | | | | | of the uniq array
* | Fix CollectionAssociation#replace to return new target (closes #6231)Piotr Sarnacki2012-05-161-0/+2
| |
* | CollectionProxy < RelationJon Leighton2012-05-111-7/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This helps bring the interfaces of CollectionProxy and Relation closer together, and reduces the delegation backflips we need to perform. For example, first_or_create is defined thus: class ActiveRecord::Relation def first_or_create(...) first || create(...) end end If CollectionProxy < Relation, then post.comments.first_or_create will hit the association's #create method which will actually add the new record to the association, just as post.comments.create would. With the previous delegation, post.comments.first_or_create expands to post.comments.scoped.first_or_create, where post.comments.scoped has no knowledge of the association.
* | Some refactor for association.kennyj2012-04-121-1/+1
|/ | | | | | | * Remove unused association_class method. * Remove a unnecessary assignment. * Move @updated to BelongsToAssociation that only reference this instance variable. * Reset @stale_state at the reset method. I think this place is right place.
* In AR depths use &:to_i before :uniq to process mixed arrays likes ["1", 1] ↵Alexey Vakhov2012-03-091-1/+1
| | | | correct
* ids_reader method fixed, test added to has_many associationgregolsen2012-01-311-1/+1
|
* Remove Array.wrap calls in ActiveRecordRafael Mendonça França2012-01-061-3/+1
|
* Use 1.9 waySantiago Pastorino2012-01-051-6/+1
|
* bypass preloading for ids_readerSergey Nartimov2011-12-181-2/+10
| | | | | when fetching ids for a collection, bypass preloading to avoid the unnecessary performance overhead
* Fix #3672 again (dependent: delete_all perf)Jon Leighton2011-12-141-0/+7
|
* load has_many associations keyed off a custom primary key if that key is ↵Brian Samson2011-11-251-1/+1
| | | | present but the record is unsaved
* Merge pull request #3507 from jmazzi/issue-3503Jeremy Kemper2011-11-031-2/+6
| | | | Preserve SELECT columns on the COUNT for finder_sql when possible
* Changed a few instances of of words in the API docs written in British ↵Oemuer Oezkir2011-07-241-1/+1
| | | | | | English to American English(according to Weber)
* Fix bug in collection_singular_ids on has many through association with ↵Anatoliy Lysenko2011-07-061-1/+1
| | | | | | | | | | | | | | | | conditions and includes, when condtions references tables from includes. Test fail because of invalid sql: ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: comments.id: SELECT "posts".id FROM "posts" INNER JOIN "readers" ON "posts"."id" = "readers"."post_id" WHERE "readers"."person_id" = 1 AND (comments.id is null) Bug described in github#925 This commit will revert fix from https://github.com/rails/rails/commit/3436fdfc12d58925e3d981e0afa61084ea34736c , but tests is ok. Bug described in #6569 ticket.
* Fixed CollectionAssociation#find to be compatible with Array#findBogdan Gusiev2011-07-051-3/+7
| | | | | In order to make CollectionAssociation behave closer to Array Add the ability to pass block to #find method just like Array#find does.
* Assign the association attributes to the associated record before the ↵Jon Leighton2011-06-301-6/+0
| | | | before_initialize callback of the record runs. Fixes #1842.
* Replace inline lambdas with named methodsJon Leighton2011-06-121-29/+42
|