Skip to content

Instantly share code, notes, and snippets.

@akinsgre
Created July 30, 2012 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akinsgre/3206666 to your computer and use it in GitHub Desktop.
Save akinsgre/3206666 to your computer and use it in GitHub Desktop.
Dependent delete on relate_to_details
class Plugin < ActiveRecord::Base
belongs_to :user
has_one :plugin_window_detail, :dependent => :delete
def private?
private_flag?
end
end
# == Schema Information
#
# Table name: plugins
#
# id :integer(4) not null, primary key
# name :string(255)
# user_id :integer(4)
# html :text
# css :text
# js :text
# created_at :datetime
# updated_at :datetime
# private_flag :boolean(1) default(FALSE)
#
class PluginWindowDetail < ActiveRecord::Base
end
# == Schema Information
#
# Table name: plugin_window_details
#
# id :integer(4) not null, primary key
# plugin_id :integer(4)
# plugin_window_id :integer(4)
# created_at :datetime
# updated_at :datetime
#
class Window < ActiveRecord::Base
belongs_to :channel
attr_accessible #none
def self.relate_to_details
class_eval <<-EOF
has_one :window_detail, :class_name => "#{self.name}Detail"
accepts_nested_attributes_for :window_detail
default_scope :include => :window_detail
EOF
end
def private?
return private_flag
end
end
# == Schema Information
#
# Table name: windows
#
# id :integer(4) not null, primary key
# channel_id :integer(4)
# position :integer(4)
# created_at :datetime
# updated_at :datetime
# html :text
# col :integer(4)
# title :string(255)
# wtype :string(255)
# name :string(255)
# type :string(255)
# private_flag :boolean(1) default(FALSE)
# show_flag :boolean(1) default(TRUE)
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment