Class: ActsAsTable::Table
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ActsAsTable::Table
- Defined in:
- app/models/acts_as_table/table.rb
Overview
ActsAsTable table.
Instance Attribute Summary collapse
-
#records_count ⇒ Integer
readonly
Returns the number of ActsAsTable records for this ActsAsTable table.
Belongs to collapse
-
#row_model ⇒ ActsAsTable::RowModel
Returns the ActsAsTable row model for this ActsAsTable table.
Has many collapse
-
#records ⇒ ActiveRecord::Relation<ActsAsTable::Record>
Returns the ActsAsTable records for this ActsAsTable table.
Instance Method Summary collapse
-
#from_row(row = []) ⇒ Array<ActsAsTable::Record>
Returns the ActsAsTable records for the given row.
Instance Attribute Details
#records_count ⇒ Integer (readonly)
Returns the number of ActsAsTable records for this ActsAsTable table.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/acts_as_table/table.rb', line 8 class Table < ::ActiveRecord::Base # @!parse # include ActsAsTable::ValueProvider # include ActsAsTable::ValueProviderAssociationMethods self.table_name = ActsAsTable.tables_table # Returns the ActsAsTable row model for this ActsAsTable table. belongs_to :row_model, **{ class_name: 'ActsAsTable::RowModel', inverse_of: :tables, required: true, } # Returns the ActsAsTable records for this ActsAsTable table. has_many :records, -> { order(position: :asc) }, **{ autosave: true, class_name: 'ActsAsTable::Record', dependent: :destroy, foreign_key: 'table_id', inverse_of: :table, validate: true, } # Returns the ActsAsTable records for the given row. # # @param [Array<String, nil>, nil] row # @return [Array<ActsAsTable::Record>] # @raise [ArgumentError] If the name of a class for a given record does not match the class name for the corresponding ActsAsTable record model. def from_row(row = []) self.row_model.from_row(row, self.records) end end |
Instance Method Details
#from_row(row = []) ⇒ Array<ActsAsTable::Record>
Returns the ActsAsTable records for the given row.
37 38 39 |
# File 'app/models/acts_as_table/table.rb', line 37 def from_row(row = []) self.row_model.from_row(row, self.records) end |
#records ⇒ ActiveRecord::Relation<ActsAsTable::Record>
Returns the ActsAsTable records for this ActsAsTable table.
23 24 25 26 27 28 29 30 |
# File 'app/models/acts_as_table/table.rb', line 23 has_many :records, -> { order(position: :asc) }, **{ autosave: true, class_name: 'ActsAsTable::Record', dependent: :destroy, foreign_key: 'table_id', inverse_of: :table, validate: true, } |
#row_model ⇒ ActsAsTable::RowModel
Returns the ActsAsTable row model for this ActsAsTable table.
16 17 18 19 20 |
# File 'app/models/acts_as_table/table.rb', line 16 belongs_to :row_model, **{ class_name: 'ActsAsTable::RowModel', inverse_of: :tables, required: true, } |