Created
July 30, 2012 12:45
-
-
Save akinsgre/3206666 to your computer and use it in GitHub Desktop.
Dependent delete on relate_to_details
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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