Module: ROM::SQL::AttributeAliasing Private

Included in:
Attribute
Defined in:
lib/rom/sql/attribute_aliasing.rb

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

Instance Method Summary collapse

Instance Method Details

#aliased(alias_name) ⇒ SQL::Attribute Also known as: as

Return a new attribute with an alias

Examples:

users[:id].aliased(:user_id)

Returns:



15
16
17
18
19
20
21
# File 'lib/rom/sql/attribute_aliasing.rb', line 15

def aliased(alias_name)
  new_name, new_alias_name = extract_alias_names(alias_name)

  super(new_alias_name).with(name: new_name).meta(
    sql_expr: alias_sql_expr(sql_expr, new_alias_name)
  )
end

#aliased_projection?TrueClass, FalseClass

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 true if this attribute is an aliased projection

Examples:

class Tasks < ROM::Relation[:memory]
  schema do
    attribute :user_id, Types::Integer, alias: :id
    attribute :name, Types::String
  end
end

Users.schema[:user_id].aliased?
# => true
Users.schema[:user_id].aliased_projection?
# => false

Users.schema[:user_id].qualified_projection.aliased?
# => true
Users.schema[:user_id].qualified_projection.aliased_projection?
# => true

Returns:

  • (TrueClass, FalseClass)


48
49
50
# File 'lib/rom/sql/attribute_aliasing.rb', line 48

def aliased_projection?
  self.meta[:sql_expr].is_a?(Sequel::SQL::AliasedExpression)
end