As far as I know, no.
But you can use single table inheritance to handle this
create_table :people do |t|
column :first_name, :string
column :last_name, :string
column :type, :string
end
class Person < ActiveRecord::Base
end
class Employee < Person
end
class Customer < Person
end
p = Person.create :first_name => "Homer", :last_name =>
"Simpson", :type
=> "Customer"
p.class
=> Customer
or just do
c = Customer.create :first_name => "Homer", :last_name =>
"Simpson
Notes:
The "type" column is absolutely necessary. It stores the class name as
a
string.
All columns used in all models must be in the person table. You may end up
with lots of null columns, but that''s usually ok.
On 6/14/06, Chris Carter <cdcarter@gmail.com>
wrote:>
> so i have a people table, and a person has a persontype. the person
> types are customer, and employee. I would like to make them into two
> models, where i can call Employee.new(:name =>
''chris'') and it would
> make a person with the name chris and the persontype of employee, and be
> able to do the same thing for Customer. is this possible while still
> using only the one person table?
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060614/2f9b75b4/attachment.html