houdini/app/models/custom_field_join.rb
2020-06-15 10:26:57 -05:00

26 lines
764 B
Ruby

# frozen_string_literal: true
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
class CustomFieldJoin < ApplicationRecord
# :supporter,
# :supporter_id,
# :custom_field_master,
# :custom_field_master_id,
# :value
validates :custom_field_master, presence: true
belongs_to :custom_field_master
belongs_to :supporter
def self.create_with_name(nonprofit, h)
cfm = nonprofit.custom_field_masters.find_by_name(h['name'])
cfm = nonprofit.custom_field_masters.create(name: h['name']) if cfm.nil?
create(value: h['value'], custom_field_master_id: cfm.id, supporter_id: h['supporter_id'])
end
def name
custom_field_master.name
end
end