Class: ROM::SQL::Relation
- Inherits:
-
Relation
- Object
- Relation
- ROM::SQL::Relation
- Defined in:
- lib/rom/sql/relation.rb,
lib/rom/sql/relation/reading.rb,
lib/rom/sql/relation/writing.rb
Overview
Sequel-specific relation extensions
Defined Under Namespace
Constant Summary
Constants included from ROM::SQL
CheckConstraintError, ConstraintError, DatabaseError, ERROR_MAP, ForeignKeyConstraintError, NoAssociationError, NotNullConstraintError, Rollback, UniqueConstraintError, VERSION
Class Method Summary collapse
- .associations ⇒ Object private
-
.inherited(klass) ⇒ Object
private
Set default dataset for a relation sub-class.
- .primary_key(value) ⇒ Object deprecated Deprecated.
- .primary_key_header(db, table) ⇒ Object private
Instance Method Summary collapse
-
#columns ⇒ Array<Symbol>
private
Return raw column names.
-
#header ⇒ Header
private
Return a header for this relation.
-
#table ⇒ Symbol
private
Return table name from relation’s sql statement.
Methods included from Reading
#avg, #count, #distinct, #exclude, #fetch, #first, #group, #group_and_count, #inner_join, #invert, #last, #left_join, #limit, #map, #max, #min, #offset, #order, #pluck, #prefix, #project, #qualified, #qualified_columns, #rename, #reverse, #select, #select_append, #select_group, #sum, #union, #unique?, #where
Methods included from Writing
#delete, #insert, #multi_insert, #update, #upsert
Methods included from ROM::SQL
Class Method Details
.associations ⇒ Object
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.
70 71 72 |
# File 'lib/rom/sql/relation.rb', line 70 def self.associations schema.associations end |
.inherited(klass) ⇒ Object
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.
Set default dataset for a relation sub-class
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rom/sql/relation.rb', line 40 def self.inherited(klass) super klass.class_eval do schema_dsl SQL::Schema::DSL schema_inferrer ROM::SQL::Schema::Inferrer dataset do table = opts[:from].first if db.table_exists?(table) pk_header = klass.primary_key_header(db, table) select(*columns).order(*pk_header.qualified) else self end end # @!method by_pk(pk) # Return a relation restricted by its primary key # @param [Object] pk The primary key value # @return [SQL::Relation] # @api public view(:by_pk, attributes[:base]) do |pk| where(primary_key => pk) end end end |
.primary_key(value) ⇒ Object
Set primary key
92 93 94 95 96 97 |
# File 'lib/rom/sql/relation.rb', line 92 def self.primary_key(value) Deprecations.announce( :primary_key, "use schema definition to configure primary key" ) option :primary_key, reader: true, default: value end |
.primary_key_header(db, table) ⇒ Object
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.
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rom/sql/relation.rb', line 75 def self.primary_key_header(db, table) names = if schema schema.primary_key_names elsif db.respond_to?(:primary_key) Array(db.primary_key(table)) else [:id] end Header.new(names, table) end |
Instance Method Details
#columns ⇒ Array<Symbol>
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 raw column names
128 129 130 |
# File 'lib/rom/sql/relation.rb', line 128 def columns @columns ||= dataset.columns end |
#header ⇒ Header
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 header for this relation
119 120 121 |
# File 'lib/rom/sql/relation.rb', line 119 def header @header ||= Header.new(selected_columns, table) end |
#table ⇒ Symbol
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 table name from relation’s sql statement
This value is used by ‘header` for prefixing column names
110 111 112 |
# File 'lib/rom/sql/relation.rb', line 110 def table @table ||= dataset.opts[:from].first end |