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

Can't destroy record #28

Closed DouweM closed 13 years ago

DouweM commented 13 years ago

I am using MySQL2 and the CITIER gem as currently available through git. I have a Status root-class and a LinkStatus subclass.

When I try to destroy either a Status or any LinkStatus, it doesn't work:

pry(main)> LinkStatus.last.destroy
citier -> Non Root Class
citier -> table_name -> link_statuses
citier -> tablename (view) -> view_link_statuses
  LinkStatus Load (3.3ms)  SELECT `view_link_statuses`.* FROM `view_link_statuses` WHERE `view_link_statuses`.`type` IN ('LinkStatus') ORDER BY `view_link_statuses`.`id` DESC LIMIT 1
   (0.1ms)  BEGIN
  SQL (0.2ms)  DELETE FROM `statuses` WHERE `statuses`.`id` IS NULL
citier -> Deleting back up hierarchy LinkStatus
  SQL (0.1ms)  DELETE FROM `link_statuses` WHERE `link_statuses`.`id` IS NULL
   (0.1ms)  COMMIT
=> #<LinkStatus id: 2, [...]>

pry(main)> Status.last.destroy
  Status Load (0.4ms)  SELECT `statuses`.* FROM `statuses` ORDER BY `statuses`.`id` DESC LIMIT 1
   (0.1ms)  BEGIN
  SQL (0.2ms)  DELETE FROM `statuses` WHERE `statuses`.`id` IS NULL
   (0.1ms)  COMMIT
=> #<Status id: 7, [...]>

As you can see, the executed DELETE query looks for a record with id IS NULL, instead of id = 2 and id = 7 respectively.

It could very well be that this isn't a bug in CITIER and that I'm doing something wrong, but I couldn't find a better place to post this.

DouweM commented 13 years ago

Fixed in pull request #31