@@ -13,13 +13,15 @@ module Types
1313 belongs_to :parent , optional : true , class_name : :Project , foreign_key : :remixed_from_id , inverse_of : :remixes
1414 has_many :remixes , dependent : :nullify , class_name : :Project , foreign_key : :remixed_from_id , inverse_of : :parent
1515 has_many :components , -> { order ( default : :desc , name : :asc ) } , dependent : :destroy , inverse_of : :project
16+ has_one :scratch_component , dependent : :destroy , inverse_of : :project , required : false
1617 has_many :project_errors , dependent : :nullify
1718 has_many_attached :images
1819 has_many_attached :videos
1920 has_many_attached :audio
2021 has_one :school_project , dependent : :destroy
2122
2223 accepts_nested_attributes_for :components
24+ accepts_nested_attributes_for :scratch_component
2325
2426 before_validation :check_unique_not_null , on : :create
2527 before_validation :create_school_project_if_needed
@@ -67,6 +69,10 @@ def components=(array)
6769 super ( array . map { |o | o . is_a? ( Hash ) ? Component . new ( o ) : o } )
6870 end
6971
72+ def scratch_component = ( value )
73+ super ( value . is_a? ( Hash ) ? ScratchComponent . new ( value ) : value )
74+ end
75+
7076 def last_edited_at
7177 # datetime that the project or one of its components was last updated
7278 [ updated_at , components . maximum ( :updated_at ) ] . compact . max
0 commit comments