Class: ROM::Schema::AssociationsDSL
- Inherits:
- BasicObject
- Defined in:
- core/lib/rom/schema/associations_dsl.rb
Overview
Additional schema DSL for definition SQL associations
This DSL is exposed in associations do .. end
blocks in schema defintions.
Instance Attribute Summary collapse
- #registry ⇒ Object readonly
- #source ⇒ Object readonly
Instance Method Summary collapse
-
#belongs_to(target, **options) ⇒ Associations::ManyToOne
Shortcut for many_to_one which sets alias automatically.
-
#has_one(target, **options) ⇒ Associations::OneToOne
Shortcut for one_to_one which sets alias automatically.
-
#many_to_many(target, **options) ⇒ Associations::ManyToMany
Establish a many-to-many association.
-
#many_to_one(target, **options) ⇒ Associations::ManyToOne
Establish a many-to-one association.
-
#one_to_many(target, **options) ⇒ Associations::OneToMany
(also: #has_many)
Establish a one-to-many association.
-
#one_to_one(target, **options) ⇒ Associations::OneToOne
Establish a one-to-one association.
-
#one_to_one_through(target, **options) ⇒ Associations::OneToOneThrough
Establish a one-to-one association with a :through option.
Instance Attribute Details
#registry ⇒ Object (readonly)
21 22 23 |
# File 'core/lib/rom/schema/associations_dsl.rb', line 21 def registry @registry end |
#source ⇒ Object (readonly)
17 18 19 |
# File 'core/lib/rom/schema/associations_dsl.rb', line 17 def source @source end |
Instance Method Details
#belongs_to(target, **options) ⇒ Associations::ManyToOne
Shortcut for many_to_one which sets alias automatically
154 155 156 |
# File 'core/lib/rom/schema/associations_dsl.rb', line 154 def belongs_to(target, **) many_to_one(dataset_name(target), as: target, **) end |
#has_one(target, **options) ⇒ Associations::OneToOne
Shortcut for one_to_one which sets alias automatically
171 172 173 |
# File 'core/lib/rom/schema/associations_dsl.rb', line 171 def has_one(target, **) one_to_one(dataset_name(target), as: target, **) end |
#many_to_many(target, **options) ⇒ Associations::ManyToMany
Establish a many-to-many association
120 121 122 |
# File 'core/lib/rom/schema/associations_dsl.rb', line 120 def many_to_many(target, **) add(::ROM::Associations::Definitions::ManyToMany.new(source, target, **)) end |
#many_to_one(target, **options) ⇒ Associations::ManyToOne
Establish a many-to-one association
137 138 139 |
# File 'core/lib/rom/schema/associations_dsl.rb', line 137 def many_to_one(target, **) add(::ROM::Associations::Definitions::ManyToOne.new(source, target, **)) end |
#one_to_many(target, **options) ⇒ Associations::OneToMany Also known as: has_many
Establish a one-to-many association
62 63 64 65 66 67 68 |
# File 'core/lib/rom/schema/associations_dsl.rb', line 62 def one_to_many(target, **) if [:through] many_to_many(target, **) else add(::ROM::Associations::Definitions::OneToMany.new(source, target, **)) end end |
#one_to_one(target, **options) ⇒ Associations::OneToOne
Establish a one-to-one association
87 88 89 90 91 92 93 |
# File 'core/lib/rom/schema/associations_dsl.rb', line 87 def one_to_one(target, **) if [:through] one_to_one_through(target, **) else add(::ROM::Associations::Definitions::OneToOne.new(source, target, **)) end end |
#one_to_one_through(target, **options) ⇒ Associations::OneToOneThrough
Establish a one-to-one association with a :through option
103 104 105 |
# File 'core/lib/rom/schema/associations_dsl.rb', line 103 def one_to_one_through(target, **) add(::ROM::Associations::Definitions::OneToOneThrough.new(source, target, **)) end |