描述:
数据库中有一个 表 : users
id : 1
name : myname
role : customer
id :2
name :amdin
role :admin
还有两个model :user, customer
问题:
在CustomerController中使用
customers = Customer.find(:all) #实际数据是 User.find(:all, :conditions =>[:role => 'customer'])
请问如何在customer model 中设置一下? 或者别的方法做到?
用set_table_name不是可以做到吗 这样customeru就是访问的users数据库了
看看[url]http://samung.iteye.com/blog/287978[/url]
[code="ruby"]class Mod < ActiveRecord::Base
has_one :resource ,:as => :ph
end [/code]
和
[code="ruby"]class Operation < ActiveRecord::Base
has_one :resource ,:as => :ph
end [/code]
google 一下 STI(single table inheritance)
AR的做法是增加一个列, type(string类型)