Module: Binda::FieldableAssociationHelpers::FieldableRelationHelpers

Included in:
Binda::FieldableAssociationHelpers
Defined in:
app/models/concerns/binda/fieldable_association_helpers/fieldable_relation_helpers.rb

Instance Method Summary collapse

Instance Method Details

#get_dependent_components(field_slug) ⇒ Object

Alias for get_related_components



31
32
33
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_relation_helpers.rb', line 31

def get_dependent_components(field_slug)
	get_related_components(field_slug)
end

#get_owner_components(field_slug) ⇒ array

Get all components which owns a relation where the current instance is a dependent

Parameters:

  • field_slug (string)

    The slug of the field setting of the relation

Returns:

  • (array)

    An array of components and/or boards

Raises:

  • (ArgumentError)


39
40
41
42
43
44
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_relation_helpers.rb', line 39

def get_owner_components(field_slug)
	# obj = self.owner_relations.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }
	obj = Relation.where(field_setting_id: B.get_field_settings(field_slug)).includes(dependent_relations: :dependent).where(binda_relation_links: {dependent_type: self.class.name})
	raise ArgumentError, "There isn't any relation associated to the current slug (#{field_slug}) where the current instance (#{self.class.name} ##{self.id}) is a dependent.", caller if obj.nil?
	return obj
end

Get related boards

Parameters:

  • field_slug (string)

    The slug of the field setting

Returns:

  • (array)

    An array of boards

Raises:

  • (ArgumentError)


60
61
62
63
64
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_relation_helpers.rb', line 60

def get_related_boards(field_slug)
	obj = self.relations.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }
	raise ArgumentError, "There isn't any related field associated to the current slug (#{field_slug}) on instance (#{self.class.name} ##{self.id}).", caller if obj.nil?
	return obj.dependent_relations.map{|relation| relation.dependent}
end

Get related components

Parameters:

  • field_slug (string)

    The slug of the field setting

Returns:

  • (array)

    An array of components

Raises:

  • (ArgumentError)


24
25
26
27
28
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_relation_helpers.rb', line 24

def get_related_components(field_slug)
	obj = self.relations.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }
	raise ArgumentError, "There isn't any related field associated to the current slug (#{field_slug}) on instance (#{self.class.name} ##{self.id}).", caller if obj.nil?
	return obj.dependent_relations.map{|relation| relation.dependent}
end

#has_dependent_components(field_slug) ⇒ Object

Alias for has_related_components



16
17
18
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_relation_helpers.rb', line 16

def has_dependent_components(field_slug)
	has_related_components(field_slug)
end

Check if has related boards

Parameters:

  • field_slug (string)

    The slug of the field setting

Returns:

  • (boolean)

Raises:

  • (ArgumentError)


50
51
52
53
54
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_relation_helpers.rb', line 50

def has_related_boards(field_slug)
	obj = self.relations.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }
	raise ArgumentError, "There isn't any related field associated to the current slug (#{field_slug}) on instance (#{self.class.name} ##{self.id}).", caller if obj.nil?
	return obj.dependent_relations.any?
end

Check if has related components

Parameters:

  • field_slug (string)

    The slug of the field setting

Returns:

  • (boolean)

Raises:

  • (ArgumentError)


9
10
11
12
13
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_relation_helpers.rb', line 9

def has_related_components(field_slug)
	obj = self.relations.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }
	raise ArgumentError, "There isn't any related field associated to the current slug (#{field_slug}) on instance (#{self.class.name} ##{self.id}).", caller if obj.nil?
	return obj.dependent_relations.any?
end