Rails User.all bug found in Hartl's scaffold app - Why is User.all not responding to command like an array of hashes? - ruby-on-rails-3

I discovered this bug while reproducing Michael Hartl's scaffolded rails demo_app from his rails tutorial.
I went into the rails console
rails c
I asked for the User.all array of hashes and out it through its paces:
2.0.0-p0 :012 > User.all
User Load (0.3ms) SELECT "users".* FROM "users"
=> [#<User id: 2, name: "Lisa Johnson", email: "ljohnson#yahoo.com", created_at: "2013-04-02 03:30:06", updated_at: "2013-04-02 03:30:06">]
2.0.0-p0 :013 > User.all[0]
User Load (0.2ms) SELECT "users".* FROM "users"
=> #<User id: 2, name: "Lisa Johnson", email: "ljohnson#yahoo.com", created_at: "2013-04-02 03:30:06", updated_at: "2013-04-02 03:30:06">
2.0.0-p0 :015 > User.all[0]['id']
User Load (0.2ms) SELECT "users".* FROM "users"
=> 2
So far, so good.
However, User.all does not respond to the command to list say just the id's or names of all users:
2.0.0-p0 :017 > User.all { |i| puts i['id'] }
User Load (0.2ms) SELECT "users".* FROM "users"
=> [#<User id: 2, name: "Lisa Johnson", email: "ljohnson#yahoo.com", created_at: "2013-04-02 03:30:06", updated_at: "2013-04-02 03:30:06"gt;]
2.0.0-p0 :019 >User.all{ |i| puts i['name'] }
User Load (0.3ms) SELECT "users".* FROM "users"
=> [#<User id: 2, name: "Lisa Johnson", email: "ljohnson#yahoo.com", created_at: "2013-04-02 03:30:06", updated_at: "2013-04-02 03:30:06">]
Assigning an arbitrary variable a to the array of hashes User.all resolves the issue:
2.0.0-p0 :021 >a.each {|i| puts i['id'] }
2
=> [#<User id: 2, name: "Lisa Johnson", email: "ljohnson#yahoo.com", created_at: "2013-04-02 03:30:06", updated_at: "2013-04-02 03:30:06">]
2.0.0-p0 :022 >a.each {|i| puts i['name'] }
Lisa Johnson
=> [#<User id: 2, name: "Lisa Johnson", email: "ljohnson#yahoo.com", created_at: "2013-04-02 03:30:06", updated_at: "2013-04-02 03:30:06">]
This User.all issue affects at least ruby versions 1.9.2,1.9.3 and 2.0.0. Whoever is responsible for writing the gem that created User.all needs to go over his all method. For whatever it's worth, I am working with rails 3.2.12

Nothing to discuss - its a straightforward bug report. If there is a question, the question would be "why is User.all is not behaving like the array of hashes it is?"

Related

How to detach the associated record in memory only which is related to has_many association in rails-4.2

In Rails 3.2.16 we are having association as user has_many activities while querying has_many association, we can detach the association in memory by using the pop method which will not update the database, once we reloading the main object then it will remove changes in memory.
**Rails 3.12.16**
#user = User.find(1) # Identifying the user
#user.activities # Fetching activities of that user having one record
[#<Activity id: 205501, title: "Logging", user_id: 1, created_at: "2020-06-01 14:29:23", updated_at: "2020-06-01 14:29:43">]
#user.activities.pop # will detach the first object and #activities will have an empty array in the whole application until reloading main object
[]
#user.activities # will return []
#user.activities.build(id: 1234567, title: "Signing Out") # will return only new built object
[#<Activity id: 1234567, title: "Signing Out", user_id: 1>]
#user.reload
#user.activities # will retain the association records
[#<Activity id: 205501, title: "Logging", user_id: 133, created_at: "2020-06-01 14:29:23", updated_at: "2020-06-01 14:29:43">]
**Rails 4.2**
#user = User.find(1) # Identifying the user
#user.activities # Fetching activities of that user
[#<Activity id: 205501, title: "Logging", user_id: 133, created_at: "2020-06-01 14:29:23", updated_at: "2020-06-01 14:29:43">]
#user.activities.pop # will throw an error because ActiveRecord::CollectionProxy is not having the pop method
# So we tried the to_a method
#user.activities.to_a.pop # it is affecting the array but not detaching the association in memory due it is not mutated
[]
#user.activities # > Rails 4 the association is reloaded defaultly
[#<Activity id: 205501, title: "Logging", user_id: 133, created_at: "2020-06-01 14:29:23", updated_at: "2020-06-01 14:29:43">]
# If we are trying to build a new object
#user.activities.build(id: 1234567, title: "Signing Out")
#user.activities # We are receiving both existing and new build object but we needed only newly build object like rails 3
[#<Activity id: 205501, title: "Logging", user_id: 133, created_at: "2020-06-01 14:29:23", updated_at: "2020-06-01 14:29:43">,
#<Activity id: 1234567, title: "Signing Out", user_id: 1>]
As Rails Document suggests to use the delete method,
but it is updating the association record in Database and removing the record as well.
Anyone can suggest the replacement of the rails 3.12.16 pop method, in rails 4.2
Currently, we are upgrading our Ruby on Rails application from 3 to 4,2.
Gems Listing:-
Rails 4.2.0 -
1) ruby (2.3.3)
2) activerecord (4.2.0)
Rails 3.2.16 -
1) ruby (2.0.0)
2) activerecord (3.2.16)
According to a rails contributor, this is expected behavior.
See here: https://github.com/rails/rails/issues/30612#issuecomment-329884753
I suspect you're going to have to find a different way to do what you want to do, but you haven't really stated what you're trying to accomplish.

Ruby on Rails 4: has_secure_password is not asking for a password confirmation when creating new user

I am currently writing an app using RoR4 and am having trouble with authentication. Even though I've added has_secure_password to the User model, I still seem to be able to create a new user without having to provide a password confirmation.
2.1.2 :012 > me = User.create(:institution_id => 1, :email => "me#myschool.edu", :password => "mypassword")
(0.1ms) BEGIN
User Exists (0.3ms) SELECT 1 AS one FROM `users` WHERE `users`.`email` = BINARY 'me#myschool.edu' LIMIT 1
SQL (0.2ms) INSERT INTO `users` (`created_at`, `email`, `institution_id`, `password_digest`, `updated_at`) VALUES ('2014-07-14 20:02:34', 'me#myschool.edu', 1, '$2a$10$sD2N.2nxhYO7egzzWxfF5.cdIZ4ds41.sU93Ja3E9Q0qAOaABdZb6', '2014-07-14 20:02:34')
(8.2ms) COMMIT
=> #<User id: 5, institution_id: 1, first_name: nil, last_name: nil, email: "me#myschool.edu", blurb: nil, facebook_link: nil, facebook_token: nil, password_digest: "$2a$10$sD2N.2nxhYO7egzzWxfF5.cdIZ4ds41.sU93Ja3E9Q0...", api_key: nil, active: false, created_at: "2014-07-14 20:02:34", updated_at: "2014-07-14 20:02:34", authentication_token: nil>
Why is this happening? Shouldn't has_secure_password always require a password confirmation as well??
Thanks for the help
Make sure you followed these things:
add gem 'bcrypt' to gem file.
Next:
have a password_digest attribute
Next:
class User < ActiveRecord::Base
has_secure_password
end
Then you can test it:
user = User.new(name: 'david', password: '', password_confirmation: 'nomatch')
user.save # => false, password required
user.password = 'mUc3m00RsqyRe'
user.save # => false, confirmation doesn't match
user.password_confirmation = 'mUc3m00RsqyRe'
user.save # => true
user.authenticate('notright') # => false
user.authenticate('mUc3m00RsqyRe') # => user
User.find_by(name: 'david').try(:authenticate, 'notright') # => false
User.find_by(name: 'david').try(:authenticate, 'mUc3m00RsqyRe') # => user

self-referential has_many trouble

I getting troubles with a self referential table.
I got an orb model which can hold planets, stars and moons. I want to tell that one thing "orbit" another
i look at the rails guide, but i coulnd get it working
My model:
class Orb < ActiveRecord::Base
belongs_to :orb_type
has_and_belongs_to_many :books
belongs_to :orbit, :class_name => "Orb"
has_many :orbs, :class_name => "Orb", :foreign_key => "orb_id"
attr_accessible :descr, :nome, :orb_type_id, :book_ids, :orb_id
validates :nome, uniqueness: true, presence: true
end
I think i am using bad relations names (maybe in the wrong way around)
1.9.3-p448 :002 > earth = Orb.find(1)
Orb Load (0.2ms) SELECT "orbs".* FROM "orbs" WHERE "orbs"."id" = ? LIMIT 1 [["id", 1]]
=> #<Orb id: 1, nome: "Terra", descr: "123123", orb_type_id: 1, created_at: "2013-09-25 14:53:35", updated_at: "2013-09-25 14:57:40", orb_id: nil>
1.9.3-p448 :003 > moon = Orb.find(2)
Orb Load (0.2ms) SELECT "orbs".* FROM "orbs" WHERE "orbs"."id" = ? LIMIT 1 [["id", 2]]
=> #<Orb id: 2, nome: "Lua", descr: "asd", orb_type_id: 2, created_at: "2013-09-25 14:53:46", updated_at: "2013-09-25 14:55:31", orb_id: nil>
1.9.3-p448 :004 > sun = Orb.find(3)
Orb Load (0.2ms) SELECT "orbs".* FROM "orbs" WHERE "orbs"."id" = ? LIMIT 1 [["id", 3]]
=> #<Orb id: 3, nome: "Sol", descr: "asd", orb_type_id: 3, created_at: "2013-09-25 14:53:55", updated_at: "2013-09-25 14:53:55", orb_id: nil>
1.9.3-p448 :006 > moon.orbit=earth
=> #<Orb id: 1, nome: "Terra", descr: "123123", orb_type_id: 1, created_at: "2013-09-25 14:53:35", updated_at: "2013-09-25 14:57:40", orb_id: nil>
1.9.3-p448 :007 > earth.orbit=sun
=> #<Orb id: 3, nome: "Sol", descr: "asd", orb_type_id: 3, created_at: "2013-09-25 14:53:55", updated_at: "2013-09-25 14:53:55", orb_id: nil>
1.9.3-p448 :008 > earth
=> #<Orb id: 1, nome: "Terra", descr: "123123", orb_type_id: 1, created_at: "2013-09-25 14:53:35", updated_at: "2013-09-25 14:57:40", orb_id: nil>
1.9.3-p448 :009 > sun
=> #<Orb id: 3, nome: "Sol", descr: "asd", orb_type_id: 3, created_at: "2013-09-25 14:53:55", updated_at: "2013-09-25 14:53:55", orb_id: nil>
1.9.3-p448 :010 > moon
=> #<Orb id: 2, nome: "Lua", descr: "asd", orb_type_id: 2, created_at: "2013-09-25 14:53:46", updated_at: "2013-09-25 14:55:31", orb_id: nil>
in the end nothing get associated, the FK still nill.
The collun orb_id was added latter on the model. I setup a migration and added it in the model. I don't think it could be related to my problem...
EDIT:
Now everything is even odd. i change my model to:
class Orb < ActiveRecord::Base
belongs_to :orb_type
has_and_belongs_to_many :books
belongs_to :orbit, :class_name => "Orb"
has_many :orbits, :class_name => "Orb", :foreign_key => "orb_id"
attr_accessible :descr, :nome, :orb_type_id, :book_ids, :orb_id
validates :nome, uniqueness: true, presence: true
end
In rails console (rails c) i try:
1.9.3-p448 :008 > earth = Orb.find(1)
Orb Load (0.2ms) SELECT "orbs".* FROM "orbs" WHERE "orbs"."id" = ? LIMIT 1 [["id", 1]]
=> #<Orb id: 1, nome: "Terra", descr: "", orb_type_id: 1, created_at: "2013-09-25 17:51:26", updated_at: "2013-09-25 18:16:58", orb_id: 3>
1.9.3-p448 :009 > earth.orbit
=> nil
1.9.3-p448 :010 > earth.orbits
Orb Load (0.3ms) SELECT "orbs".* FROM "orbs" WHERE "orbs"."orb_id" = 1
=> [#<Orb id: 2, nome: "Lua", descr: "", orb_type_id: 2, created_at: "2013-09-25 17:51:40", updated_at: "2013-09-25 18:17:31", orb_id: 1>]
1.9.3-p448 :011 >
What the heck? orbits seen to return what i want, but it i try to use it:
1.9.3-p448 :004 > earth.orbits.nome
NoMethodError: Orb Load (0.4ms) SELECT "orbs".* FROM "orbs" WHERE "orbs"."orb_id" = 1
undefined method `nome' for #<ActiveRecord::Relation:0x00000003d593c0>
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.12/lib/active_record/relation/delegation.rb:45:in `method_missing'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.12/lib/active_record/associations/collection_proxy.rb:100:in `method_missing'
from (irb):4
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Technically, it's not great that you have planets, stars, and moons all within the same model. They all behave differently and should each warrant their own model. E.g. a star will never orbit a planet, and a planet will never orbit a moon (by definition). By structuring your database the way you have, you're setting yourself up for corrupted data, which will always happen if you allow it to.
If you must have them all within the Orb model, I would recommend 2 models: 1 for the Orbs (stars, planets, moons), and 1 for the Orbits. The Orbit class would essentially be a table like so:
Orbit model:
| id | orbited_id | orbiter_id |
--------------------------------
| 0 | planet_id | moon_id |
| 1 | star_id | planet_id |
| 2 | planet_id | moon_id |
| ...| etc | etc |
And then you can set up the association in orb.rb:
has_and_belongs_to_many :orbits,
class_name: 'Orb',
join_table: :orbits,
foreign_key: :orbited_id,
association_foreign_key: :orbiter_id,
uniq: true
This will allow you to do things like
>> sun = Orb.find(1)
>> sun.orbits
=> [ <Orb mercury>, <Orb venus>, ..., <Orb pluto> ]
i figure it out. I should make the rom in the table withe the name of relation (orbit_id) instead of doing it the table name (orb_id)
Fixing that everything started to work nicely :)
has_many :orbters, class_name: "Orb", foreign_key: "orbit_id"
belongs_to :orbit, class_name: "Orb"

setting an atttribute in rails console - transaction rolled back

I've used this forum gem before and also been able to set the forem_admin to "true" using the console. However, this time it's rolling back the transaction when I try to save.
You can see below that I set the forem_admin to "true," saved it, it rolled back the transaction (which means it didn't save), I did "u" and it showed forem_admin = true but when I restarted the console it showed forem_admin = false.
If anyone's familiar with this gem, I think this forem_state attribute is new, so I'm wondering if anything's changed.
I'm not an SQL pro but one thing that looks funny to me is the line
"users"."id" != 5
I would have expected it to have been "users"."id" = 5 i.e. with no "!", because the id of the user "signuplinks" is 5.
this is a rails 3.2 app
update when I do u.errors after u.save, I'm getting this error message
#messages={:password=>["can't be blank"]}
Console
ruby-1.9.3-rc1 :001 > u = User.last
User Load (0.2ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
=> #<User id: 5, email: "myemail#gmail.com", encrypted_password: "$2a$10$axjwcO.kU4/mqC9Llyj.b.r/2jJULnWKmG7Pi3Zu1AE3...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2012-03-05 03:37:59", last_sign_in_at: "2012-03-05 03:37:59", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", confirmation_token: nil, confirmed_at: "2012-03-05 03:37:58", confirmation_sent_at: "2012-03-05 03:34:33", unconfirmed_email: nil, created_at: "2012-03-05 03:34:33", updated_at: "2012-03-05 03:37:59", name: "signuplinks", country: "Canada", image: "3.png", forem_admin: false, forem_state: "pending_review">
ruby-1.9.3-rc1 :002 > u.forem_admin = true
=> true
ruby-1.9.3-rc1 :003 > u.save
(0.1ms) begin transaction
User Exists (0.2ms) SELECT 1 FROM "users" WHERE (LOWER("users"."name") = LOWER('signuplinks') AND "users"."id" != 5) LIMIT 1
User Exists (0.1ms) SELECT 1 FROM "users" WHERE (LOWER("users"."email") = LOWER('signuplinks#gmail.com') AND "users"."id" != 5) LIMIT 1
(0.1ms) rollback transaction
=> false
ruby-1.9.3-rc1 :004 > u
=> #<User id: 5, email: "myemail#gmail.com", encrypted_password: "$2a$10$axjwcO.kU4/mqC9Llyj.b.r/2jJULnWKmG7Pi3Zu1AE3...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2012-03-05 03:37:59", last_sign_in_at: "2012-03-05 03:37:59", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", confirmation_token: nil, confirmed_at: "2012-03-05 03:37:58", confirmation_sent_at: "2012-03-05 03:34:33", unconfirmed_email: nil, created_at: "2012-03-05 03:34:33", updated_at: "2012-03-05 03:37:59", name: "signuplinks", country: "Canada", image: "3.png", forem_admin: true, forem_state: "pending_review">
ruby-1.9.3-rc1 :005 > exit
Michael-Pro:ic michl$ rails c
Loading development environment (Rails 3.2.1)
ruby-1.9.3-rc1 :001 > u = User.last
User Load (0.3ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
=> #<User id: 5, email: "myemail#gmail.com", encrypted_password: "$2a$10$axjwcO.kU4/mqC9Llyj.b.r/2jJULnWKmG7Pi3Zu1AE3...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2012-03-05 03:37:59", last_sign_in_at: "2012-03-05 03:37:59", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", confirmation_token: nil, confirmed_at: "2012-03-05 03:37:58", confirmation_sent_at: "2012-03-05 03:34:33", unconfirmed_email: nil, created_at: "2012-03-05 03:34:33", updated_at: "2012-03-05 03:37:59", name: "signuplinks", country: "Canada", image: "3.png", forem_admin: false, forem_state: "pending_review">
actually, this was my own fault. Thanks to #muistooshort for pointing out problem probably is in model. I had included "password" in the validates_presence of validator which was stopping me from changing user details in the console (without including password)

Tricky active record relationships - polymorphic bi-directional self-referential

How would you model the references and citations to publications (articles, books, chapters, etc...)?
A publication can be an article, book or a chapter and it has many references to other publications and other publications refer to it (call these citations)
I need to be able to list the relationships among the publications: The references in a publication and the citations from other publications to this publication
My initial understanding is that this would be a polymorphic relationship to handle the different types of publications and that it would require a bidirectionalself join.
My stab at it
Publication
belongs_to :writing, :polymorphic =>true
has_and_belongs_to_many :references
:class_name => "Publication"
:join_table => 'reference_citation'
:foreign_key => 'reference_id'
:foreign_key => 'citation_id'
Book, Chapter, Article all have:
has_many :publications :as =>writing
I find this a bit confusing so any suggestions that would help clarify it would be great. Even object and field naming suggestions.
[I asked a less clear version of this question here.]
I also probably need to use has many through because I will need the ability to destroy the relationship
Here's a solution using a self-referential relationship using single table inheritance. Use these commands to create the app:
$ rails myproject
$ cd myproject
$ script/generate model publication type:string name:string
$ script/generate model citation publication_id:integer reference_id:integer
The setup the relationships this way:
class Publication < ActiveRecord::Base
has_many :citations
has_many :cited_publications, :through => :citations, :source => :reference
has_many :references, :foreign_key => "reference_id", :class_name => "Citation"
has_many :refered_publications, :through => :references, :source => :publication
end
class Citation < ActiveRecord::Base
belongs_to :publication
belongs_to :reference, :class_name => "Publication"
end
class Article < Publication
end
class Book < Publication
end
class Chapter < Publication
end
Now we can create the DB and try it out from the console:
$ rake db:migrate
$ script/console
Loading development environment (Rails 2.2.2)
>> a = Article.create!(:name => "Article")
=> #<Article id: 1, ...>
>> b = Book.create!(:name => "Book")
=> #<Book id: 2, ...>
>> a.citations.create(:reference => b)
=> #<Citation id: 1, publication_id: 1, reference_id: 2, created_at: "2009-02-15 14:13:15", updated_at: "2009-02-15 14:13:15">
>> a.citations
=> [#<Citation id: 1, ...>]
>> a.references
=> []
>> b.citations
=> []
>> b.references
=> [#<Citation id: 1, publication_id: 1, reference_id: 2, created_at: "2009-02-15 14:13:15", updated_at: "2009-02-15 14:13:15">]
>> a.cited_publications
=> [#<Book id: 2, type: "Book", name: "Book", created_at: "2009-02-15 14:11:00", updated_at: "2009-02-15 14:11:00">]
>> a.refered_publications
=> []
>> b.cited_publications
=> []
>> b.refered_publications
=> [#<Article id: 1, type: "Article", name: "Article", created_at: "2009-02-15 14:10:51", updated_at: "2009-02-15 14:10:51">]
Here's a solution that doesn't use Single Table Inheritance for the publications. That means that there are articles, books and chapters tables, instead of one publications table. Here are the commands to run to create the app:
$ rails myproject
$ cd myproject
$ script/generate model book name:string
$ script/generate model chapter name:string
$ script/generate model article name:string
$ script/generate model citation publication_type:string publication_id:integer reference_type:string reference_id:integer
Create this file in lib/acts_as_publication.rb:
module ActsAsPublication
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def acts_as_publication
has_many :citations, :as => :publication
has_many :references, :as => :reference, :class_name => "Citation"
end
end
end
Create this file in config/initializers/acts_as_publication.rb:
ActiveRecord::Base.send(:include, ActsAsPublication)
Then call that in each model, Article, Book and Chapter, like this:
class Article < ActiveRecord::Base
acts_as_publication
end
Then add these relationships in app/models/citation.rb:
class Citation < ActiveRecord::Base
belongs_to :publication, :polymorphic => true
belongs_to :reference, :polymorphic => true
end
Now we can create the DB and try it out from the console:
$ rake db:migrate
$ script/console
Loading development environment (Rails 2.2.2)
>> a = Article.create!(:name => "a")
=> #<Article id: 1, ...>
>> b = Article.create!(:name => "b")
=> #<Article id: 2, ...>
>> Citation.create!(:publication => a, :reference => b)
=> #<Citation id: 1, publication_type: "Article", publication_id: 1, reference_type: "Article", reference_id: 2, created_at: "2009-02-15 13:14:27", updated_at: "2009-02-15 13:14:27">
>> a.citations
=> [#<Citation id: 1, ...>]
>> a.references
=> []
>> b.citations
=> []
>> b.references
=> [#<Citation id: 1, ...>]
>> Book.create!(:name => "foo")
=> #<Book id: 1, name: "foo", created_at: "2009-02-15 13:18:23", updated_at: "2009-02-15 13:18:23">
>> a.citations.create(:reference => Book.first)
=> #<Citation id: 2, publication_type: "Article", publication_id: 1, reference_type: "Book", reference_id: 1, created_at: "2009-02-15 13:18:52", updated_at: "2009-02-15 13:18:52">
>> Book.first.references
=> [#<Citation id: 2, ...>]
>> a.citations
=> [#<Citation id: 1, publication_type: "Article", publication_id: 1, reference_type: "Article", reference_id: 2, created_at: "2009-02-15 13:14:27", updated_at: "2009-02-15 13:14:27">, #<Citation id: 2, publication_type: "Article", publication_id: 1, reference_type: "Book", reference_id: 1, created_at: "2009-02-15 13:18:52", updated_at: "2009-02-15 13:18:52">]
I have an incomplete answer over at http://github.com/francois/so-536261/tree/master
Basically, the DB schema does support your use case, but ActiveRecord doesn't. The solution will probably involve using find by sql or other tricks.