Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:dependent => :destroy #35

Open
surzycki opened this issue Oct 20, 2011 · 2 comments
Open

:dependent => :destroy #35

surzycki opened this issue Oct 20, 2011 · 2 comments

Comments

@surzycki
Copy link

Doesn't seem to work for model associations on citier child models

Any model association on a citier child model will not be destroy when the parent is destroyed

ie

has_many :promotions, :dependent => :destroy

is on a citier model

promotions will hang around even after the citier model is wacked

@jonlhouse
Copy link

Hmm... which fork are you using? My first test of dependent => destroy seems to work

My model looks like:

class Condition < ActiveRecord::Base
  acts_as_citier
  belongs_to :testable, :polymorphic => true
end

class ConditionSet < Condition
  acts_as_citier
  has_many conditions, :as => :testable, :dependent => destroy
end

And my rspec test using FactoryGirl to create one condition_set object with 3 associated conditions (of different types) look like this:

it "should destroy child associations" do
  cond = Factory(:complex_cond_set)
  (conds = cond.conditions).should_not be_empty
  Condition.all.should_not be_empty
  cond.destroy
  conds.conditions.should be_empty
  conds.each { |c| Condition.find_by_id(c.id).should be_nil }
end

This passes. I still haven't associated a non-citier model with a citier one, that's next up. For example: Model A has_many :conditions, :as => :testable, :dependent => :destroy I'll let you know if that passes or not.

@surzycki
Copy link
Author

This passes. I still haven't associated a non-citier model with a citier one, that's next up. For example: Model A has_many :conditions, :as => :testable, :dependent => :destroy I'll let you know if that passes or not.

Is what is not working for me.

As well. If you don't save your citier model before attaching a non citier association to it, it will not properly populate the foreign keys...

Let me know if you have a different experience. I really love the concept, the performance gains from not having to do joins is a real bonus....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants