Skip to content

Commit 53f052e

Browse files
committed
Working but strange implemntation.
TODO : fix move casting stuff from serialize and place them in cast obviously
1 parent fa9bca5 commit 53f052e

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

lib/couchbase-orm/changeable.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,10 @@ def create_dirty_methods(name, meth)
367367

368368
def create_setters(name)
369369
define_method("#{name}=") do |new_attribute_value|
370+
type = self.class.attribute_types[name.to_s]
371+
casted_value = type.cast( type.serialize type.cast new_attribute_value)
370372
previous_value = attributes[name.to_s]
371-
ret = super(new_attribute_value)
373+
ret = super(casted_value)
372374
if previous_value != attributes[name.to_s]
373375
changed_attributes.merge!(Hash[name, [previous_value, attributes[name.to_s]]])
374376
end

lib/couchbase-orm/persistence.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ def _create_record(*_args, **options)
264264
if options[:transcoder].nil?
265265
options[:transcoder] = CouchbaseOrm::JsonTranscoder.new(json_validation_config: self.class.json_validation_config)
266266
end
267-
pp serialized_attributes
268267
resp = self.class.collection.upsert(self.id, serialized_attributes.except("id").merge(type: self.class.design_document), Couchbase::Options::Upsert.new(**options))
269268
# Ensure the model is up to date
270269
@__metadata__.cas = resp.cas

lib/couchbase-orm/utilities/query_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ def serialize_value(key, value_before_type_cast)
120120
value =
121121
if value_before_type_cast.is_a?(Array)
122122
value_before_type_cast.map do |v|
123-
attribute_types[key.to_s].serialize(attribute_types[key.to_s].cast(v))
123+
attribute_types[key.to_s].serialize(v)
124124
end
125125
else
126-
attribute_types[key.to_s].serialize(attribute_types[key.to_s].cast(value_before_type_cast))
126+
attribute_types[key.to_s].serialize(value_before_type_cast)
127127
end
128128
CouchbaseOrm.logger.debug { "convert_values: #{key} => #{value_before_type_cast.inspect} => #{value.inspect} #{value.class} #{attribute_types[key.to_s]}" }
129129
value

0 commit comments

Comments
 (0)