aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* | Fix error message when trying to create an associated recordRafael Mendonça França2014-12-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | This error only happens when the foreign key is missing. Before this fix the following exception was being raised: NoMethodError: undefined method `val' for #<Arel::Nodes::BindParam:0x007fc64d19c218> Now the message is: ActiveRecord::UnknownAttributeError: unknown attribute 'foreign_key' for Model.
* | Inject the `PredicateBuilder` into the `Relation` instanceSean Griffin2014-12-261-7/+3
|/ | | | | | | Construction of relations can be a hotspot, we don't want to create one of these in the constructor. This also allows us to do more expensive things in the predicate builder's constructor, since it's created once per AR::Base subclass
* Move PredicateBuilder instantiation to constructorMelanie Gilman2014-12-031-4/+5
| | | | In order to maintain thread safety and prevent race condition from memoization.
* Refactor `PredicateBuilder` from singleton to instanceMelanie Gilman2014-12-021-0/+4
|
* Update Arel usage for rails/arel#98fc259Sean Griffin2014-11-291-2/+2
| | | | | `where_sql` now requires that we pass it an engine. None of the manager classes take an engine in their constructor.
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-4/+4
|
* Reword documentation for update_allRené van den Berg2014-11-241-8/+1
| | | It now contains a carefully formulated reference to the "current relation" which might help clarify that the receiving will generate its own scope, escaping the need for explicitly referencing `default_scope` which is, after all, just another way of specifying a scope and nothing special.
* Explain that default_scope also influences update_allRené van den Berg2014-11-201-5/+12
| | | | | This was not explicitly stated before and I needed to try it out to be certain. A little explicit statement in the API docs might help here.
* pull the preloader allocation in to a factory methodAaron Patterson2014-11-181-1/+5
|
* Remove the unused second argument to `substitute_at`Sean Griffin2014-11-171-1/+1
| | | | Oh hey, we got to remove some code because of that!
* rm `reorder_bind_params`Sean Griffin2014-11-171-1/+0
| | | | | | Arel handles this for us automatically. Updated tests, as BindParam is no longer a subclass of SqlLiteral. We should remove the second argument to substitute_at entirely, as it's no longer used
* Use a bound parameter for the "id = " portion of update statementsSean Griffin2014-11-011-2/+8
| | | | | | We need to re-order the bind parameters since the AST returned by the relation will have the where statement as the first bp, which breaks on PG.
* Use bind values for joined tables in where statementsSean Griffin2014-11-011-1/+1
| | | | | | | | | | | | | | | In practical terms, this allows serialized columns and tz aware columns to be used in wheres that go through joins, where they previously would not behave correctly. Internally, this removes 1/3 of the cases where we rely on Arel to perform type casting for us. There were two non-obvious changes required for this. `update_all` on relation was merging its bind values with arel's in the wrong order. Additionally, through associations were assuming there would be no bind parameters in the preloader (presumably because the where would always be part of a join) [Melanie Gilman & Sean Griffin]
* Don't needlessly alphabetize columns for insert/updateSean Griffin2014-11-011-4/+3
| | | | | This slightly simplifies the code, and reduces the number of times we need to iterate over the attributes by one.
* delete leftover JoinOperation structswapdisc2014-10-141-2/+0
|
* Clarify `#update_all` doc about value processingNicolas Cavigneaux2014-10-141-1/+2
| | | | | | | | | This clarify the fact that `#update_all` doesn't type-cast passed values and that these values are written as-is in the SQL DB. Fix #17242 [ci skip]
* Move #encode_with to RelationGustavo Beathyate2014-07-151-0/+5
|
* Merge pull request #14971 from versioncontrol/#14785Yves Senn2014-06-061-1/+8
|\ | | | | | | Baseclass becomes! subclass
| * Fix Baseclass becomes! subclass.Edo Balvers2014-05-131-1/+8
| |
* | Fix `Relation#delete_all` inconsistencyLeandro Facchinetti2014-05-161-3/+13
|/ | | | | | | | | When relation scopes include one of `uniq`, `group`, `having` or `offset`, the generated query ignores them and that causes unintended records to be deleted. This solves the issue by restricting the deletion when those scopes are present. rails/rails#11985
* Merge branch 'master' into adequaterecordAaron Patterson2014-04-141-5/+6
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (70 commits) [ci skip] Added link to ruby-lang.org installation. Use the index on hidden field `collection_check_boxes` respects `:index` option for the hidden filed name. docs, double meaning of `serialize` argument. Closes #14284. Just call read_attribute, no need to use `send`. - Fix lingering reference to `:text` instead of the newer `:plain` - Section references `form_tag` instead of the `form_for` used in the example again, read_attribute is public, so just call it read_attribute is public, so we should just call it Disable assest cache store in docs [ci skip] Make counter cache decrementation on destroy idempotent Write the failing test case for concurrent counter cache [ci skip] Use plain underscore instead of "\_". Update documentation to use Rails.application instead Add a changelog entry for #14546 [ci skip] Move tests for deep_dup and duplicable to object directory Missing 'are' in note - [ci skip] CollectionHelpers now accepts a readonly option Fix a few typos [ci skip] Bundle tzinfo-data on :x64_mingw (64-bit Ruby on Windows). don't bother with an offset if the offset is zero ...
| * Make the comparison between 'Relation' and 'AssociationRelation'Lauro Caetano2014-04-121-1/+1
| | | | | | | | consistent.
| * The comparison between `Relation` and `CollectionProxy` should be consistent.Lauro Caetano2014-04-111-0/+2
| | | | | | | | | | | | | | | | | | | | | | Example: author.posts == Post.where(author_id: author.id) # => true Post.where(author_id: author.id) == author.posts # => true Fixes #13506
| * Merge pull request #14711 from ↵Rafael Mendonça França2014-04-111-3/+2
| |\ | | | | | | | | | | | | | | | swoker/activerecord_fix_aggregate_methods_with_select Activerecord fix aggregate methods with select
| | * Fix error for aggregate methods with select, see issue #13648Simon Woker2014-04-101-3/+2
| | |
| * | Merge pull request #12829 from iantropov/issue_insert_via_hmt_scope_3548Rafael Mendonça França2014-04-101-2/+2
| |\ \ | | |/ | |/| | | | | | | | | | | | | Fix insertion of records for hmt association with scope Conflicts: activerecord/CHANGELOG.md
| | * Fix insertion of records for hmt association with scope, fix #3548Ivan Antropov2013-11-171-2/+2
| | |
* | | propogate bind values collected in arel to SQL generationAaron Patterson2014-04-111-1/+2
| | |
* | | remove the bind substitution visitor. to_sql should never return bind valuesAaron Patterson2014-04-091-5/+6
| | |
* | | use the compile method so we do not have to specify the collectors in this caseAaron Patterson2014-04-091-2/+1
| | |
* | | working against arel/collector branchAaron Patterson2014-04-091-1/+2
| | |
* | | where_values should extract the value of the Casted nodeAaron Patterson2014-04-071-1/+7
| | | | | | | | | | | | makes adequaterecord work with arel master.
* | | Merge branch 'master' into adequaterecordAaron Patterson2014-04-071-1/+1
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (122 commits) Rails.application should be set inside before_configuration hook remove check for present? from delete_all Remove useless begin..end Build the reverse_order on its proper method. Use connection-specific bytea escaping Ignore order when doing count. make enums distinct per class Remove unused `subclass_controller_with_flash_type_bar` var from flash test. fix CollectionProxy delete_all documentation Added OS X specific commands to installation guide [ci skip] Recommended using homebrew for installing MySQL and PostgreSQL Fix setup of adding _flash_types test. Use SVG version of travis build status badge [skip ci] W3C CSP document moved to gihub.io URL [ci skip] sprockets-rails was released Fix the test defining the models in the right place Add CHANGELOG entry for #11650 [ci skip] Declare the assets dependency Use sass-rails 4.0.3 Make possible to use sprockets-rails 2.1 add missing parentheses to validates_with documentation [skip ci] ...
| * | Merge pull request #11650 from prathamesh-sonpatki/renameRafael Mendonça França2014-04-041-1/+1
| |\ \ | | | | | | | | | | | | Renamed private methods _create_record and _update_record
| | * | [Active Record] Renamed private methods create_record and update_recordPrathamesh Sonpatki2014-02-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | This is to ensure that they are not accidentally called by the app code. They are renamed to _create_record and _update_record respectively. Closes #11645
* | | | Merge branch 'master' into adequaterecordAaron Patterson2014-03-131-1/+10
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (108 commits) make tests pass on Ruby 2.2 Use Sqlite3 adapter in examples use the body proxy to freeze headers just ask the response for the commit status, we do not need to ask the jar only write the jar if the response isn't committed Fix a grammatical error in the i18n guide [ci skip] use method_defined? to check whether or not a method is defined Enhance docs for update_attribute [ci-skip] Change usec to 0 on tests that compare seconds Unit test for mysql quote time usec Changelog entry for mysql56 microseconds Test microsecond on mysql 5.6 MySQL 5.6 and later supports microsecond precision in datetime. [ci skip] Add documentation for original_fullpath. Remove mocking on save, when not necessary comment why we are modifying global state. [ci skip] `change_table` supports `citext`. Follow up to #12523. Removed unnecessary command "application" register OID for PostgreSQL citex datatype [Troy Kruthoff & Lachlan Sylvester] Fixes STI when 2+ levels deep. ...
| * | | `includes` uses SQL parsing when String joins are involved.Yves Senn2014-02-281-1/+10
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a partial revert of 22b3481ba2aa55fad1f9a5db94072312b345fb55. The current implementation of `references_eager_loaded_tables?` needs to know every table involved in the query. With the current API this is not possible without SQL parsing. While a2dab46cae35a06fd5c5500037177492a047c252 deprecated SQL parsing for `includes`. It did not issue deprecation warnings when String joins are involved. This resulted in a breaking change after the deprecated behavior was removed (22b3481ba2aa55fad1f9a5db94072312b345fb55). We will need to rethink the usage of `includes`, `preload` and `eager_load` but for now, this brings back the old *working* behavior.
* | | Merge branch 'master' into adequaterecordAaron Patterson2014-02-171-2/+3
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (311 commits) Add a missing changelog entry for #13981 and #14035 Revert "Fixed plugin_generator test" implements new option :month_format_string for date select helpers [Closes #13618] add factory methods for empty alias trackers guarantee a list in the alias tracker so we can remove a conditional stop exposing table_joins make most parameters to the AliasTracker required make a singleton for AssociationScope pass the association and connection to the scope method pass the tracker down the stack and construct it in the scope method clean up add_constraints signature remove the reflection delegate remove klass delegator remove railties changes. fixes #14054 remove chain delegate remove scope_chain delegate Add verb to sanitization note fix path shown in mailer's templates updated Travis build status image url fix guide active_support_core_extensions. add Note to String#indent [ci skip] ... Conflicts: activerecord/lib/active_record/associations/join_dependency.rb activerecord/test/cases/associations/association_scope_test.rb
| * | Remove duplicate mergekei2014-01-221-1/+0
| | |
| * | Remove missed usage of @first variableCarlos Antonio da Silva2014-01-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | With the introduction of `#second` method and friends, we added an offsets hash which replaced the @first variable, so removing it from the reset method to avoid creating an unused variable now. Introduced in bc625080308e4853ae3036f2ad74fe3826e463ef.
| * | Remove unneded argumentRafael Mendonça França2014-01-201-2/+2
| | | | | | | | | | | | This variable is internal and should not be exposed to end users
| * | Ensure #second acts like #first AR finderJason Meller2014-01-201-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit bring the famous ordinal Array instance methods defined in ActiveSupport into ActiveRecord as fully-fledged finders. These finders ensure a default ascending order of the table's primary key, and utilize the OFFSET SQL verb to locate the user's desired record. If an offset is defined in the query, calling #second adds to the offset to get the actual desired record. Fixes #13743.
* | | Revert "adding set_binds"Aaron Patterson2014-01-171-8/+0
| | | | | | | | | | | | This reverts commit 474ebc55bd13ad58626a49dfc44c8e6407813935.
* | | replace bind values on calls to to_sqlAaron Patterson2014-01-131-4/+4
| | |
* | | adding bind values to the manager objectAaron Patterson2014-01-131-1/+1
| | |
* | | Merge branch 'master' into set_bindsAaron Patterson2014-01-111-99/+84
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (2794 commits) doc, API example on how to use `Model#exists?` with multiple IDs. [ci skip] Restore DATABASE_URL even if it's nil in connection_handler test [ci skip] - error_messages_for has been deprecated since 2.3.8 - lets reduce any confusion for users Ensure Active Record connection consistency Revert "ask the fixture set for the sql statements" Check `respond_to` before delegation due to: https://github.com/ruby/ruby/commit/d781caaf313b8649948c107bba277e5ad7307314 Adding Hash#compact and Hash#compact! methods MySQL version 4.1 was EOL on December 31, 2009 We should at least recommend modern versions of MySQL to users. clear cache on body close so that cache remains during rendering add a more restricted codepath for templates fixes #13390 refactor generator tests to use block form of Tempfile Fix typo [ci skip] Move finish_template as the last public method in the generator Minor typos fix [ci skip] make `change_column_null` reversible. Closes #13576. create/drop test and development databases only if RAILS_ENV is nil Revert "Speedup String#to" typo fix in test name. [ci skip]. `core_ext/string/access.rb` test what we are documenting. Fix typo in image_tag documentation ... Conflicts: activerecord/lib/active_record/associations/join_dependency/join_association.rb activerecord/lib/active_record/relation/query_methods.rb
| * | Fix ActiveRecord::Relation#unscopeJon Leighton2013-11-201-1/+1
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I'm pretty confused about the addition of this method. The documentation says that it was intended to allow the removal of values from the default scope (in contrast to #except). However it behaves exactly the same as except: https://gist.github.com/jonleighton/7537008 (other than having a slightly enhanced syntax). The removal of the default scope is allowed by 94924dc32baf78f13e289172534c2e71c9c8cade, which was not a change we could make until 4.1 due to the need to deprecate things. However after that change #unscope still gives us nothing that #except doesn't already give us. However there *is* a desire to be able to unscope stuff in a way that persists across merges, which would allow associations to be defined which unscope stuff from the default scope of the associated model. E.g. has_many :comments, -> { unscope where: :trashed } So that's what this change implements. I've also corrected the documentation. I removed the guide references to #except as I think unscope really supercedes #except now. While we're here, there's also a potential desire to be able to write this: has_many :comments, -> { unscoped } However, it doesn't make sense and would not be straightforward to implement. While with #unscope we're specifying exactly what we want to be removed from the relation, with "unscoped" we're just saying that we want it to not have some things which were added earlier on by the default scope. However in the case of an association, we surely don't want *all* conditions to be removed, otherwise the above would just become "SELECT * FROM comments" with no foreign key constraint. To make the above work, we'd have to somehow tag the relation values which get added when evaluating the default scope in order to differentiate them from other relation values. Which is way too much complexity and therefore not worth it when most use cases can be satisfied with unscope. Closes #10643, #11061.
| * pass the pk to compile_updateAaron Patterson2013-11-161-1/+1
| |
| * Fix test name [ci skip]Carlos Antonio da Silva2013-11-141-2/+0
| |
| * Fix that eager loading of polymorphic associations did not work with ↵David Heinemeier Hansson2013-11-141-1/+9
| | | | | | | | association empty?/any? predicates any more (there is still a problem when select is applied to a relation, or if you try association#exists? -- but its easier to work around)