與AR和多態工作時,我來到了一個問題,這裏的描述,ActiveRecord的,的has_many,多態和STI
class Base < ActiveRecord::Base; end
class Subscription < Base
set_table_name :subscriptions
has_many :posts, :as => :subscriptable
end
class Post < ActiveRecord::Base
belongs_to :subscriptable, :polymorphic => true
end
,
>> s = Subscription.create(:name => 'test')
>> s.posts.create(:name => 'foo', :body => 'bar')
,它創造了一個Post
,如:
#<Post id: 1, name: "foo", body: "bar", subscriptable_type: "Base", subscriptable_id: 1, created_at: "2010-05-10 12:30:10", updated_at: "2010-05-10 12:30:10">
的subscriptable_type
爲Base
但Subscription
,任何人都可以給我一個手呢?
階級基礎有其表或者是一個抽象類? – 2010-05-10 13:31:46
@Vlad Zloeanu,類Base沒有自己的表,它只是ActiveRecord :: Base的一個子代 – leomayleomay 2010-05-10 13:58:35