我使用單表繼承在我的應用程序和運行合適的班級爲構建繼承用戶從一個祖先的問題。舉例來說,有以下設置: class School < ActiveRecord::Base
has_many :users
end
class User < ActiveRecord::Base
attr_accessible :type #etc...
belongs_to
我有以下設置,模型客戶端是模型聯繫人的子類。 STI表是聯繫人。 然後在測試代碼中調用 it "should have the right clients in the right order" do
@producer.clients.should == [a_client, b_client]
end
用SQL語句錯誤地解決不存在客戶表中的ORDER BY子句時,我得到一個錯誤
我有一個STI模型,我希望可以使用ElasticSearch和Tire進行搜索。我遇到的問題是,當Tyre創建映射時,它似乎忽略了第二個模型的自定義分析器。以下是我的模型的一個例子。 class Account < ActiveRecord::Base
attr_accessible :name, :type
include Tire::Model::Search
想不通爲什麼會發生: class Foo < ActiveRecord::Base
belongs_to :belongable, :polymorphic => true
def after_save
if belongable.kind_of?(User)
send(:some_method)
end
end
end
cla
我使用STI(正確的,我保證!)爲對象的一個關係: class Walrus < ActiveRecord::Base
has_one :bubbles
end
class Bubbles < ActiveRecord::Base
belongs_to :walrus
before_save :set_origin
private
d
我第一次使用STI創建了一個應用程序,並且我偶然發現了一個令人困惑的障礙。 考慮以下兩種型號,並繼承: User.rb
class User < ActiveRecord::Base
attr_accessible :email, :first_name, :last_name, #more follows
Waiter.rb
class Waiter < User
我在/服務員/
在我的Rails應用程序我有模特這樣 class Account < ActiveRecord::Base
class Account::Bonus < Account
class Account::Virtual < Account
...more
而且這樣 class DiscountSystem < ActiveRecord::Base
class DiscountSystem: