jeudi 27 mars 2014

Rails child find by id returns the parent class object


Vote count:

0




I have parent class called Field



class Field < ActiveRecord::Base

end


And a child class called ProfileField



class ProfileField < Field
def self.base_class ; self ; end
def self.use_base_class; ProfileField; end
self.table_name = "fields"

def field_type
return "profile_field"
end
end


I have a database table "fields" and there is column called field_type. I created a Field object using Field.create with null in the field_type column. I also created a ProfileField object using ProfileField.create and gave a the type "profile_field".


let's say the id for Field object (parent class) is 10 and the child Object ProfileFiled id is 11. When I do ProfileField.find(10) i will get a ProfileField object back. I will also get a Profile Object back when I do Profile.find(10). Shouldn't I not get anything when I do ProfileField.find(10) since the Object with id 10 was a Profile Object and not a ProfileField Object?



asked 21 secs ago






Aucun commentaire:

Enregistrer un commentaire