class User < ActiveRecord::Base
has_many :posts
end
class Post < ActiveRecord::Base
belongs_to :user
end
In irb:
> u = User.first
=> #<xxxxx>
> u.posts.class
=> Array
My env:
$ruby -v
ruby 1.9.2p312
$rails --version
--version
Rails 3.1.0
I remember that almost all relation query return an ActiveRecord::Relation in rails3;
What is wrong?
ps: I need to get the “klass” from the ActiveRecord::Relation object;
davidb is correct about the has_many, but I assume you want the class without hitting the db. Use this:
(Disclaimer: Uses internal ActiveRecord methods and probably won’t work if
Postuses STI)