Class: ROM::SQL::Schema::DSL Private

Inherits:
ROM::Schema::DSL
  • Object
show all
Defined in:
lib/rom/sql/schema/dsl.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Extended schema DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#associations_dslObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
# File 'lib/rom/sql/schema/dsl.rb', line 12

def associations_dsl
  @associations_dsl
end

Instance Method Details

#associations(&block) ⇒ AssociationDSL

Define associations for a relation

Examples:

class Users < ROM::Relation[:sql]
  schema(infer: true) do
    associations do
      has_many :tasks
      has_many :posts
      has_many :posts, as: :priority_posts, view: :prioritized
      belongs_to :account
    end
  end
end

class Posts < ROM::Relation[:sql]
  schema(infer: true) do
    associations do
      belongs_to :users, as: :author
    end
  end

  view(:prioritized) do
    where { priority <= 3 }
  end
end

Returns:

  • (AssociationDSL)


43
44
45
# File 'lib/rom/sql/schema/dsl.rb', line 43

def associations(&block)
  @associations_dsl = AssociationsDSL.new(relation, &block)
end

#callObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return a schema



50
51
52
53
54
# File 'lib/rom/sql/schema/dsl.rb', line 50

def call
  SQL::Schema.define(
    relation, opts.merge(attributes: attributes.values, attr_class: SQL::Attribute)
  )
end