- 05 1月, 2013 2 次提交
-
-
由 Rafael Mendonça França 提交于
This reverts commit 162e2859. This commit was added by mistake, sorry
🙇 -
由 Cédric FABIANSKI 提交于
- Reverting #a3cf03ef fixes the issue Conflicts: activerecord/test/cases/relations_test.rb
-
- 30 11月, 2012 1 次提交
-
-
由 Jon Leighton 提交于
At present, ActiveRecord::Delegation compiles delegation methods on a global basis. The compiled methods apply to all subsequent Relation instances. This creates several problems: 1) After Post.all.recent has been called, User.all.respond_to?(:recent) will be true, even if User.all.recent will actually raise an error due to no User.recent method existing. (See #8080.) 2) Depending on the AR class, the delegation should do different things. For example, if a Post.zip method exists, then Post.all.zip should call it. But this will then result in User.zip being called by a subsequent User.all.zip, even if User.zip does not exist, when in fact User.all.zip should call User.all.to_a.zip. (There are various variants of this problem.) We are creating these compiled delegations in order to avoid method missing and to avoid repeating logic on each invocation. One way of handling these issues is to add additional checks in various places to ensure we're doing the "right thing". However, this makes the compiled methods signficantly slower. In which case, there's almost no point in avoiding method_missing at all. (See #8127 for a proposed solution which takes this approach.) This is an alternative approach which involves creating a subclass of ActiveRecord::Relation for each AR class represented. So, with this patch, Post.all.class != User.all.class. This means that the delegations are compiled for and only apply to a single AR class. A compiled method for Post.all will not be invoked from User.all. This solves the above issues without incurring significant performance penalties. It's designed to be relatively seamless, however the downside is a bit of complexity and potentially confusion for a user who thinks that Post.all and User.all should be instances of the same class. Benchmark --------- require 'active_record' require 'benchmark/ips' class Post < ActiveRecord::Base establish_connection adapter: 'sqlite3', database: ':memory:' connection.create_table :posts def self.omg :omg end end relation = Post.all Benchmark.ips do |r| r.report('delegation') { relation.omg } r.report('constructing') { Post.all } end Before ------ Calculating ------------------------------------- delegation 4392 i/100ms constructing 4780 i/100ms ------------------------------------------------- delegation 144235.9 (±27.7%) i/s - 663192 in 5.038075s constructing 182015.5 (±21.2%) i/s - 850840 in 5.005364s After ----- Calculating ------------------------------------- delegation 6677 i/100ms constructing 6260 i/100ms ------------------------------------------------- delegation 166828.2 (±34.2%) i/s - 754501 in 5.001430s constructing 116575.5 (±18.6%) i/s - 563400 in 5.036690s Comments -------- Bear in mind that the standard deviations in the above are huge, so we can't compare the numbers too directly. However, we can conclude that Relation construction has become a little slower (as we'd expect), but not by a huge huge amount, and we can still construct a large number of Relations quite quickly.
-
- 19 11月, 2012 1 次提交
-
-
由 Carlos Antonio da Silva 提交于
-
- 18 11月, 2012 1 次提交
-
-
由 Dieter Komendera 提交于
This didn't work in rails 3.1. See #2303 for more information and original pull request.
-
- 29 10月, 2012 1 次提交
-
-
由 Juanjo Bazán 提交于
-
- 19 10月, 2012 2 次提交
-
-
由 Jon Leighton 提交于
-
由 Jon Leighton 提交于
This is similar to #first_or_create, but slightly different and a nicer API. See the CHANGELOG/docs in the commit. Fixes #7853
-
- 12 10月, 2012 1 次提交
-
-
由 Tima Maslyuchenko 提交于
-
- 10 10月, 2012 1 次提交
-
-
由 Yves Senn 提交于
-
- 24 8月, 2012 1 次提交
-
-
由 Isaac Sanders 提交于
This is a cleaner version of #6916. Closes #3165.
-
- 19 8月, 2012 1 次提交
-
-
由 Ernie Miller 提交于
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.
-
- 17 8月, 2012 1 次提交
-
-
由 Ernie Miller 提交于
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
-
- 15 8月, 2012 1 次提交
-
-
由 Roman Shatsov 提交于
-
- 03 8月, 2012 1 次提交
-
-
由 Jon Leighton 提交于
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.
-
- 02 8月, 2012 1 次提交
-
-
由 Jon Leighton 提交于
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
-
- 31 7月, 2012 1 次提交
-
-
由 Bogdan Gusiev 提交于
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.
-
- 28 7月, 2012 1 次提交
-
-
由 Jon Leighton 提交于
It doesn't serve much purpose now that ActiveRecord::Base.all returns a Relation. The code is moved to active_record_deprecated_finders.
-
- 27 7月, 2012 1 次提交
-
-
由 Jon Leighton 提交于
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.
-
- 13 7月, 2012 1 次提交
-
-
由 Jon Leighton 提交于
-
- 07 7月, 2012 2 次提交
-
-
由 Jon Leighton 提交于
-
由 Damien Mathieu 提交于
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.
-
- 06 7月, 2012 1 次提交
-
-
由 Jon Leighton 提交于
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.
-
- 22 6月, 2012 1 次提交
-
-
由 Jon Leighton 提交于
-
- 03 6月, 2012 1 次提交
-
-
由 Akira Matsuda 提交于
-
- 01 6月, 2012 1 次提交
-
-
由 Akira Matsuda 提交于
now we can invoke previously added scope extension methods
-
- 21 5月, 2012 1 次提交
-
-
由 Ivan Kukobko 提交于
-
- 18 5月, 2012 2 次提交
-
-
由 Jon Leighton 提交于
-
由 Jon Leighton 提交于
-
- 17 5月, 2012 1 次提交
-
-
由 Radoslav Stankov 提交于
Record.from("(#{sub_query.to_sql})") -> Record.from(sub_query) Record.from("(#{sub_query.to_sql}) a") -> Record.from(sub_query, :a)
-
- 11 5月, 2012 1 次提交
-
-
由 Andrew White 提交于
-
- 06 5月, 2012 1 次提交
-
-
由 Jon Leighton 提交于
Revert "Merge pull request #5494 from armstrjare/active_record_relation_keep_association_join_context_on_merge" This reverts commit dcd04e76, reversing changes made to 58a49875.
-
- 05 5月, 2012 1 次提交
-
-
由 Marcelo Silveira 提交于
-
- 04 5月, 2012 1 次提交
-
-
由 Jared Armstrong 提交于
-
- 30 4月, 2012 1 次提交
-
-
由 Francesco Rodriguez 提交于
-
- 27 4月, 2012 3 次提交
-
-
由 Jon Leighton 提交于
-
由 Jon Leighton 提交于
-
由 Jon Leighton 提交于
-
- 26 4月, 2012 2 次提交
-
-
由 Jon Leighton 提交于
-
由 Jon Leighton 提交于
-