Class: Gitlab::Reflections::Relationships::Relationship
- Inherits:
-
Object
- Object
- Gitlab::Reflections::Relationships::Relationship
- Includes:
- ActiveModel::Attributes, ActiveModel::Model
- Defined in:
- lib/gitlab/reflections/relationships/relationship.rb
Overview
Represents a single relationship in the relationship collection between database tables.
Constant Summary collapse
- VALID_ASSOCIATION_TYPES =
%w[ has_many has_one belongs_to has_and_belongs_to_many has_many_attached has_one_attached ].freeze
Instance Method Summary collapse
- #polymorphic? ⇒ Boolean
- #polymorphic_belongs_to? ⇒ Boolean
- #polymorphic_has_association? ⇒ Boolean
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
Instance Method Details
#polymorphic? ⇒ Boolean
59 60 61 |
# File 'lib/gitlab/reflections/relationships/relationship.rb', line 59 def polymorphic? polymorphic end |
#polymorphic_belongs_to? ⇒ Boolean
63 64 65 |
# File 'lib/gitlab/reflections/relationships/relationship.rb', line 63 def polymorphic_belongs_to? polymorphic? && relationship_type == 'many_to_one' end |
#polymorphic_has_association? ⇒ Boolean
67 68 69 |
# File 'lib/gitlab/reflections/relationships/relationship.rb', line 67 def polymorphic_has_association? polymorphic? && relationship_type != 'many_to_one' end |
#to_h ⇒ Object
71 72 73 |
# File 'lib/gitlab/reflections/relationships/relationship.rb', line 71 def to_h attributes.compact.symbolize_keys end |
#to_json(*args) ⇒ Object
75 76 77 |
# File 'lib/gitlab/reflections/relationships/relationship.rb', line 75 def to_json(*args) to_h.to_json(*args) end |