[Rails] Re: Determine type in polymorphic relation

2009-09-23 Thread Ilan Berci
Heinz Strunk wrote: > First of all thank you guys! I think what Valentin wrote is just what I > was looking for. Person, Car, Truck was just an example. It's a lot more > complexe in my application and you can't just merge these two different > models into one and add a :type. > > I'll do it l

[Rails] Re: Determine type in polymorphic relation

2009-09-23 Thread Heinz Strunk
First of all thank you guys! I think what Valentin wrote is just what I was looking for. Person, Car, Truck was just an example. It's a lot more complexe in my application and you can't just merge these two different models into one and add a :type. I'll do it like Valentin suggested. Thanks a

[Rails] Re: Determine type in polymorphic relation

2009-09-23 Thread pepe
I'm not sure of what you need to do but I'll assume that you just want to create an association between a person and a vehicle of type car or truck (or whatever). I am assuming that you have STI built into your vehicles table, with a column named 'type' that stores the type of vehicle ('Car'/'Tru

[Rails] Re: Determine type in polymorphic relation

2009-09-22 Thread Valentin Mihov
I think that you should create some kind of an interface, for example Vehicle, like this: class Vehicle < ActiveRecord::Base belongs_to :person, :polymorphic => true end After that you should make the inherited models Car and Truck: class Car < Vehicle end class Truck < Vehicle end and fina