lib/lotus/model/adapters/sql/collection.rb in lotus-model-0.2.1 vs lib/lotus/model/adapters/sql/collection.rb in lotus-model-0.2.2
- old
+ new
@@ -53,11 +53,14 @@
# @return the primary key of the created record
#
# @api private
# @since 0.1.0
def insert(entity)
- super _serialize(entity)
+ serialized_entity = _serialize(entity)
+ serialized_entity[_identity] = super(serialized_entity)
+
+ _deserialize(serialized_entity)
end
# Filters the current scope with a `limit` directive.
#
# @param args [Array] the array of arguments
@@ -176,11 +179,14 @@
# @see Lotus::Model::Adapters::Sql::Command#update
#
# @api private
# @since 0.1.0
def update(entity)
- super _serialize(entity)
+ serialized_entity = _serialize(entity)
+ super(serialized_entity)
+
+ _deserialize(serialized_entity)
end
# Resolves self by fetching the records from the database and
# translating them into entities.
#
@@ -199,9 +205,29 @@
#
# @api private
# @since 0.1.0
def _serialize(entity)
@mapped_collection.serialize(entity)
+ end
+
+ # Deserialize the given entity after it was persisted in the database.
+ #
+ # @return [Lotus::Entity] the deserialized entity
+ #
+ # @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