Skip to content

Instantly share code, notes, and snippets.

@ewilliam
Last active March 25, 2018 19:27
Show Gist options
  • Save ewilliam/b2f9b84e6f81d8e596bf750e2feaff46 to your computer and use it in GitHub Desktop.
Save ewilliam/b2f9b84e6f81d8e596bf750e2feaff46 to your computer and use it in GitHub Desktop.
dependent destroy issue
class Scheme < ApplicationRecord
has_one :logo, as: :imageable, class_name: 'Image', dependent: :destroy
has_many :steps, class_name: 'Scheme::Step', dependent: :destroy
has_many :screens,
through: :steps, source: :steppable, source_type: 'Screen'
has_many :screen_groups,
through: :steps, source: :steppable, source_type: 'Screen::Group'
has_many :scheme_responses, class_name: 'Scheme::Response'
accepts_nested_attributes_for :screens
enum type: {
'Survey' => 0,
'Story' => 1
}
end
class Screen < ApplicationRecord
has_many :choices, dependent: :destroy
accepts_nested_attributes_for :choices, allow_destroy: true
enum type: {
multiple_choice: 0,
multiple_select: 1,
text: 2,
number: 3,
date: 4,
read_only: 5,
participant_ID: 6
}
self.inheritance_column = :_type_disabled
end
class Scheme::Step < ApplicationRecord
belongs_to :scheme
belongs_to :steppable, polymorphic: true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment