petehamilton / citier

CITIER (Class Inheritance & Table Inheritance Embeddings for Rails) is a solution for simple Multiple Class Inheritance in Rails.
88 stars 24 forks source link

Child looses it's type when saved after being retrieved from root class #21

Open morgz opened 13 years ago

morgz commented 13 years ago

Fixed Issue with saving a child after it's retrieved from parent

Facility is my Root SwimmingPool is a subclass

Problem:

  1. Create a Facility of Type 'SwimmingPool' SwimmingPool.create(:name => 'Dan Pool', :tldc_id => 97)
  2. Retrieve it through root class f = Facility.last
  3. Save a change f.name = 'tits' f.save
  4. BOOM Our previous SwimmingPool now becomes a Facility type.

This was because when we fetch through the root we have no attributes from the child so it didn't update the child type when we saved the name change. The first run through the save that saves the root, chooses the type from the classname.

I have fixed this and it's in my fork.