Module: HQ::GraphQL::ObjectAssociation
- Defined in:
- lib/hq/graphql/object_association.rb
Defined Under Namespace
Classes: ResourceReflection, UpdatedReflection
Instance Method Summary
collapse
-
#belongs_to(name, scope = nil, **options, &block) ⇒ Object
-
#has_many(name, scope = nil, through: nil, **options, &block) ⇒ Object
-
#has_one(name, scope = nil, through: nil, **options, &block) ⇒ Object
-
#reflect_on_association(association) ⇒ Object
-
#update(name, &block) ⇒ Object
Instance Method Details
#belongs_to(name, scope = nil, **options, &block) ⇒ Object
14
15
16
|
# File 'lib/hq/graphql/object_association.rb', line 14
def belongs_to(name, scope = nil, **options, &block)
add_reflection(name, scope, options, :belongs_to, block)
end
|
#has_many(name, scope = nil, through: nil, **options, &block) ⇒ Object
23
24
25
26
|
# File 'lib/hq/graphql/object_association.rb', line 23
def has_many(name, scope = nil, through: nil, **options, &block)
raise TypeError, "has_many through is unsupported" if through
add_reflection(name, scope, options, :has_many, block)
end
|
#has_one(name, scope = nil, through: nil, **options, &block) ⇒ Object
18
19
20
21
|
# File 'lib/hq/graphql/object_association.rb', line 18
def has_one(name, scope = nil, through: nil, **options, &block)
raise TypeError, "has_one through is unsupported" if through
add_reflection(name, scope, options, :has_one, block)
end
|
#reflect_on_association(association) ⇒ Object
6
7
8
|
# File 'lib/hq/graphql/object_association.rb', line 6
def reflect_on_association(association)
resource_reflections[association.to_s]&.reflection(model_klass)
end
|
#update(name, &block) ⇒ Object
10
11
12
|
# File 'lib/hq/graphql/object_association.rb', line 10
def update(name, &block)
resource_reflections[name.to_s] = UpdatedReflection.new(name, block)
end
|