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
-
#get_dependent_components(field_slug) ⇒ Object
Alias for get_related_components.
-
#get_owner_components(field_slug) ⇒ array
Get all components which owns a relation where the current instance is a dependent.
-
#get_related_boards(field_slug) ⇒ array
Get related boards.
-
#get_related_components(field_slug) ⇒ array
Get related components.
-
#has_dependent_components(field_slug) ⇒ Object
Alias for has_related_components.
-
#has_related_boards(field_slug) ⇒ boolean
Check if has related boards.
-
#has_related_components(field_slug) ⇒ boolean
Check if has related components.
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) (field_slug) end |
#get_owner_components(field_slug) ⇒ array
Get all components which owns a relation where the current instance is a dependent
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(field_slug) ⇒ array
Get related boards
60 61 62 63 64 |
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_relation_helpers.rb', line 60 def (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(field_slug) ⇒ array
Get related components
24 25 26 27 28 |
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_relation_helpers.rb', line 24 def (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) (field_slug) end |
#has_related_boards(field_slug) ⇒ boolean
Check if has related boards
50 51 52 53 54 |
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_relation_helpers.rb', line 50 def (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 |
#has_related_components(field_slug) ⇒ boolean
Check if has related components
9 10 11 12 13 |
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_relation_helpers.rb', line 9 def (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 |