lib/lotus/model/adapters/sql/collection.rb in lotus-model-0.4.1 vs lib/lotus/model/adapters/sql/collection.rb in lotus-model-0.5.0
- old
+ new
@@ -54,11 +54,11 @@
#
# @api private
# @since 0.1.0
def insert(entity)
serialized_entity = _serialize(entity)
- serialized_entity[_identity] = super(serialized_entity)
+ serialized_entity[identity] = super(serialized_entity)
_deserialize(serialized_entity)
end
# Filters the current scope with a `limit` directive.
@@ -155,10 +155,26 @@
def select(*args)
Collection.new(__getobj__.select(*Lotus::Utils::Kernel.Array(args)), @mapped_collection)
end
end
+
+ # Filters the current scope with a `group` directive.
+ #
+ # @param args [Array] the array of arguments
+ #
+ # @see Lotus::Model::Adapters::Sql::Query#group
+ #
+ # @return [Lotus::Model::Adapters::Sql::Collection] the filtered
+ # collection
+ #
+ # @api private
+ # @since 0.5.0
+ def group(*args)
+ Collection.new(super, @mapped_collection)
+ end
+
# Filters the current scope with a `where` directive.
#
# @param args [Array] the array of arguments
#
# @see Lotus::Model::Adapters::Sql::Query#where
@@ -196,10 +212,56 @@
# @since 0.1.0
def to_a
@mapped_collection.deserialize(self)
end
+ # Select all attributes for current scope
+ #
+ # @return [Lotus::Model::Adapters::Sql::Collection] the filtered
+ # collection
+ #
+ # @api private
+ # @since 0.5.0
+ #
+ # @see http://www.rubydoc.info/github/jeremyevans/sequel/Sequel%2FDataset%3Aselect_all
+ def select_all
+ Collection.new(super(table_name), @mapped_collection)
+ end
+
+ # Use join table for current scope
+ #
+ # @return [Lotus::Model::Adapters::Sql::Collection] the filtered
+ # collection
+ #
+ # @api private
+ # @since 0.5.0
+ #
+ # @see http://www.rubydoc.info/github/jeremyevans/sequel/Sequel%2FDataset%3Ajoin_table
+ def join_table(*args)
+ Collection.new(super, @mapped_collection)
+ end
+
+ # Return table name mapped collection
+ #
+ # @return [String] table name
+ #
+ # @api private
+ # @since 0.5.0
+ def table_name
+ @mapped_collection.name
+ end
+
+ # Name of the identity column in database
+ #
+ # @return [Symbol] the identity name
+ #
+ # @api private
+ # @since 0.5.0
+ def identity
+ @mapped_collection.identity
+ end
+
private
# Serialize the given entity before to persist in the database.
#
# @return [Hash] the serialized entity
#
@@ -215,19 +277,9 @@
#
# @api private
# @since 0.2.2
def _deserialize(entity)
@mapped_collection.deserialize([entity]).first
- end
-
- # Name of the identity column in database
- #
- # @return [Symbol] the identity name
- #
- # @api private
- # @since 0.2.2
- def _identity
- @mapped_collection.identity
end
end
end
end
end