Module: UniverseCompiler::Entity::RelationsManagement

Included in:
Base
Defined in:
lib/universe_compiler/entity/relations_management.rb

Instance Method Summary collapse

Instance Method Details

#has_many(target_entity_type_or_class, name: nil, strict_type: false, with_reverse_method: nil, unique: false) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/universe_compiler/entity/relations_management.rb', line 22

def has_many(target_entity_type_or_class, name: nil, strict_type: false, with_reverse_method: nil, unique: false)
  target_entity_type = normalize_entity_type target_entity_type_or_class
  field_name = relation_field_name name, target_entity_type
  field_name = field_name.to_s.pluralize.to_sym if name.nil?
  define_constraint field_name, :has_many, target_entity_type
  define_constraint field_name, :strict_type, target_entity_type if strict_type
  return unless with_reverse_method

  define_constraint_for_reverse_method :has_many,
                                       target_entity_type,
                                       field_name,
                                       with_reverse_method,
                                       unique
end

#has_one(target_entity_type_or_class, name: nil, strict_type: false, with_reverse_method: nil, unique: false) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/universe_compiler/entity/relations_management.rb', line 8

def has_one(target_entity_type_or_class, name: nil, strict_type: false, with_reverse_method: nil, unique: false)
  target_entity_type = normalize_entity_type target_entity_type_or_class
  field_name = relation_field_name name, target_entity_type
  define_constraint field_name, :has_one, target_entity_type
  define_constraint field_name, :strict_type, target_entity_type if strict_type
  return unless with_reverse_method

  define_constraint_for_reverse_method :has_one,
                                       target_entity_type,
                                       field_name,
                                       with_reverse_method,
                                       unique
end