aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation
Commit message (Collapse)AuthorAgeFilesLines
* Rather than raising ThrowResult when construct_limited_ids_conditions comes ↵Ben Woosley2013-05-102-17/+15
| | | | | | up empty, set the relation to NullRelation and rely on its results. This will help avoid errors like 2fcafee250ee2, because in most cases NullRelation will do the right thing. Minor bonus is avoiding the use of exceptions for flow control.
* Fix that #pluck wasn't rescuing ThrowResult, meaning it would blow up when ↵Ben Woosley2013-05-101-0/+2
| | | | failing to construct_limited_ids_condition.
* Extract JoinDependency#join_relation to DRY the repeated application of the ↵Ben Woosley2013-05-102-7/+2
| | | | #join_associations.
* In #apply_join_dependency, we can apply the #where in-place because relation ↵Ben Woosley2013-05-101-1/+1
| | | | | | is always a new object. Thanks to the #except we call at the top of the method.
* DRY-up join dependency creation by extracting construct_join_depdencyBen Woosley2013-05-101-7/+5
|
* Pull the excepts into apply_join_dependency, for the sake of DRY.Ben Woosley2013-05-101-3/+4
|
* Simplify conditions within apply_join_dependencyBen Woosley2013-05-101-9/+5
|
* Move the except(:select) inside the construct_limited_ids_condition method ↵Ben Woosley2013-05-101-2/+2
| | | | to pair it closely with its motivation.
* Reject blank order_values within #columns_for_distinct, as the orders aren't ↵Ben Woosley2013-05-101-2/+2
| | | | used at all on non-postgres adapters.
* Fix that #exists? can produce invalid SQL: "SELECT DISTINCT DISTINCT"Ben Woosley2013-05-101-2/+2
| | | | | | | | | | | | 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.
* extracted piece of code into a methodNeeraj Singh2013-05-081-13/+12
| | | | | | | | | | | | | | | | In order to fix #10421 I need to enable merge to take an option so that relations could be merged without making the last where condition to win. That fix would forever reside in 4-0-stable branch and would not be merged to master since using scope without lambda has been deprecated. In this commit I have extracted code into a method and I think it makes code look better. Hence the request to merge it in both master and 4-0-stable. If there is any concern then this code can be merged only in 4-0-stable and that would be fine too.
* Handle aliased attributes in ActiveRecord::Relation.Godfrey Chan2013-05-012-8/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | 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*
* add missing :nodoc: marks to ActiveRecord::Delegation [ci skip]Francesco Rodriguez2013-04-291-3/+3
|
* When empty options passed to having clause having_values was [nil] but ↵Fyodor2013-04-231-1/+0
| | | | should be empty.
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2013-04-111-2/+1
|\ | | | | | | | | Conflicts: guides/source/action_mailer_basics.md
| * mark relation mutator as :nodoc: [ci skip]Francesco Rodriguez2013-04-021-2/+1
| |
* | Remove warningCarlos Antonio da Silva2013-04-101-2/+2
| | | | | | | | warning: `*' interpreted as argument prefix
* | converge three lines into oneNeeraj Singh2013-04-101-3/+1
| |
* | While merging relations preserve context for joinsJared Armstrong and Neeraj Singh2013-04-101-2/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #3002. Also see #5494. ``` class Comment < ActiveRecord::Base belongs_to :post end class Author < ActiveRecord::Base has_many :posts end class Post < ActiveRecord::Base belongs_to :author has_many :comments end ``` `Comment.joins(:post).merge(Post.joins(:author).merge(Author.where(:name => "Joe Blogs"))).all` would fail with `ActiveRecord::ConfigurationError: Association named 'author' was not found on Comment`. It is failing because `all` is being called on relation which looks like this after all the merging: `{:joins=>[:post, :author], :where=>[#<Arel::Nodes::Equality: ....}`. In this relation all the context that `Post` was joined with `Author` is lost and hence the error that `author` was not found on `Comment`. Ths solution is to build JoinAssociation when two relations with join information are being merged. And later while building the arel use the previously built `JoinAssociation` record in `JoinDependency#graft` to build the right from clause. Thanks to Jared Armstrong (https://github.com/armstrjare) for most of the work. I ported it to make it compatible with new code base.
* | true/false => truthy falsySteve Klabnik2013-04-021-2/+2
| |
* | Prefer find_by over dynamic finders in rdocSam Ruby2013-04-021-1/+1
| |
* | Throwing a RecordNotFound exception when a record is scanned using thewangjohn2013-04-011-11/+24
|/ | | | | inverse_of option. I've also refactored the code for raising a RecordNotFound exception when searching for records with ids.
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2013-03-301-1/+1
|\ | | | | | | | | | | | | | | | | Conflicts: activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb activerecord/test/cases/adapter_test.rb guides/source/testing.md [ci skip]
| * Fix typoCarson McDonald2013-03-221-1/+1
| | | | | | | | [ci skip]
| * Fix typo, ording to orderingCarson McDonald2013-03-181-1/+1
| | | | | | | | [ci skip]
| * Uniq cannot be used directly on an ActiveRecord model. 'DISTINCT field' is ↵Daniel Lobato2013-03-121-1/+1
| | | | | | | | the only pluck query that translates into the aforementioned SQL
* | Merge pull request #9274 from KrzysiekJ/spaces_in_scope_namesRafael Mendonça França2013-03-271-5/+3
|\ \ | | | | | | | | | Use define_method when method name contains weird characters.
| * | Use define_method when method name contains weird characters.Krzysztof Jurewicz2013-03-181-5/+3
| | |
* | | Fixed typos in activerecordPrathamesh Sonpatki2013-03-271-1/+1
| | |
* | | Fix some typos in AR- CHANGELOG, tests, method doc. fixedVipul A M2013-03-201-1/+1
| | |
* | | Merge branch 'master-sec'Aaron Patterson2013-03-181-1/+1
|\ \ \ | |/ / |/| | | | | | | | | | | | | | | | | * master-sec: fix protocol checking in sanitization [CVE-2013-1857] JDOM XXE Protection [CVE-2013-1856] fix incorrect ^$ usage leading to XSS in sanitize_css [CVE-2013-1855] stop calling to_sym when building arel nodes [CVE-2013-1854]
| * | stop calling to_sym when building arel nodes [CVE-2013-1854]Aaron Patterson2013-03-151-1/+1
| |/
* | Deprecate the `:distinct` option for `Relation#count`.Yves Senn2013-03-151-2/+7
| | | | | | | | | | | | | | We moved more and more away from passing options to finder / calculation methods. The `:distinct` option in `#count` was one of the remaining places. Since we can now combine `Relation#distinct` with `Relation#count` the option is no longer necessary and can be deprecated.
* | rename `Relation#uniq` to `Relation#distinct`. `#uniq` still works.Yves Senn2013-03-152-11/+13
|/ | | | | | | | 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`.
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2013-03-051-1/+1
|\
| * Fix WhereChain docs to mention only notErnie Miller2013-03-041-1/+1
| |
* | Remove .all usage from unscope doc examples [ci skip]Carlos Antonio da Silva2013-03-041-4/+4
| |
* | Use 1.9 hash style in changelog and doc examples [ci skip]Carlos Antonio da Silva2013-03-041-3/+3
| |
* | Created an unscope method for removing relations from a chain ofwangjohn2013-03-031-0/+94
| | | | | | | | | | relations. Specific where values can be unscoped, and the unscope method still works when relations are merged or combined.
* | Revert "Merge pull request #9207 from dylanahsmith/mysql-quote-numeric"Steve Klabnik2013-02-271-5/+0
|/ | | | | This reverts commit 408227d9c5ed7de26310d72a1a99c1ee02311c63, reversing changes made to dca0b57d03deffc933763482e615c3cf0b9a1d97.
* Expand order(:symbol) to "table".symbol to prevent broken queries on PG.Yves Senn2013-02-251-0/+5
| | | | | | | | | | Fixes #9275. When `#order` is called with a Symbol this patch will prepend the quoted_table_name. Before the postgresql adapter failed to build queries containg a join and an order with a symbol. This expansion happens for all adapters.
* Make explicit the method will raise an exceptionRafael Mendonça França2013-02-241-10/+10
| | | | Taking the wise advice of @carlosantoniodasilva
* remove AR auto-explain (config.auto_explain_threshold_in_seconds)Yves Senn2013-02-241-1/+1
| | | | | | | | | | We discussed that the auto explain feature is rarely used. This PR removes only the automatic explain. You can still display the explain output for any given relation using `ActiveRecord::Relation#explain`. As a side-effect this should also fix the connection problem during asset compilation (#9385). The auto explain initializer in the `ActiveRecord::Railtie` forced a connection.
* adds a missing LIMIT 1 in #take docsXavier Noria2013-02-231-1/+1
|
* Merge pull request #9345 from ↵Rafael Mendonça França2013-02-201-10/+10
|\ | | | | | | | | wangjohn/change_name_of_query_method_argument_checker_for_clarity Renaming the check_empty_arguments method to something more descriptive.
| * Renaming the check_empty_arguments method to something more descriptive.wangjohn2013-02-201-10/+10
| | | | | | | | | | The function is now called has_arguments? so that it's easier to tell that it's just checking to see if the args are blank or not.
* | removes some remaining relation bang methods documentation [ci skip]Xavier Noria2013-02-201-3/+0
| |
* | adds an example in the docs of #not with multiple conditions [ci skip]Xavier Noria2013-02-201-4/+8
|/
* Added comments about the check_empty_arguments method which is calledwangjohn2013-02-201-11/+27
| | | | | for query methods in a where_clause. Also, modified the CHANGELOG entry because it had false information and added tests.
* Raise an error when query methods have blank arguments, and when blank ↵John J Wang2013-02-191-9/+23
| | | | arguments are meaningless.