【发布时间】:2009-01-26 16:55:40
【问题描述】:
有没有一种方法可以在 Rails 中获取特定模型所属的模型列表?
例如:
class Project < ActiveRecord::Base
has_one :status
...
end
class Task < ActiveRecord::Base
has_one :status
...
end
class Status < ActiveRecord::Base
belongs_to :project
belongs_to :task
# this is where I want to be able to pass in an array of the associations' class
# names (to be used for checking input) rather than having to do w%{ project task }
# which leaves it open to failure if I add new associations in future
validates_inclusion_of :status_of, :in => ?
...
end
希望这有某种意义!
【问题讨论】:
标签: ruby-on-rails activerecord associations