Skip to content
Open

Sql #104

Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions FMDB.podspec

This file was deleted.

5 changes: 1 addition & 4 deletions lib/motion_model.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'motion-require'
require 'motion-support'

%w(*.rb model/*.rb adapters/*.rb).each do |path|
%w(*.rb model/*.rb adapters/*.rb adapters/sql/sql_db_adapter.rb adapters/sql/sqlite3_adapter.rb adapters/sql/*.rb).each do |path|
Motion::Require.all(Dir.glob(File.expand_path("../../motion/#{path}", __FILE__)))
end
2 changes: 1 addition & 1 deletion motion/adapters/sql/fmdb_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def execute_sql(sql)
if rset
result = []
while rset.next do
result << rset.resultDictionary
result << rset.resultDict
end
end
else
Expand Down
2 changes: 2 additions & 0 deletions motion/adapters/sql/sql_condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def to_sql_str
values = @value.map { |v| v.is_a?(Numeric) ? v : %Q["#{v}"] }
elsif @value.is_a?(Range)
values = [@value.min, @value.max]
elsif @value.is_a?(TrueClass) || @value.is_a?(FalseClass)
value = @value.to_i
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is TrueClass#to_i an RM extension?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is. Before this fix "where(current: true)" was being translated to WHERE ("users"."current" = "true") and it should be WHERE ("users"."current" = 1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does value = @value work?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is working here. Maibe caling @value.dup it would be more appropriate. I`m not sure.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For true/false I assume the boolean should be passed through, if FMDB handles booleans directly which I would assume it does. No dup necessary: a = true; b = a; b = false; a # => true

else
value = %Q["#{@value}"]
end
Expand Down
2 changes: 1 addition & 1 deletion motion/adapters/sql/sql_db_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def log(sql, result)

def execute
result = @db_adapter.execute_sql(self)
log(@sql, result)
log(@sql, result) if RUBYMOTION_ENV == 'development'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably do this at the app level

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.

result
end
end
Expand Down
9 changes: 9 additions & 0 deletions motion/adapters/sql/sql_model_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,15 @@ def get_loaded_attr(col)
_col.type == :belongs_to? ? get_attr(name) : relation(_col).loaded
end

def reload
_new_record = self.class.find(self.id)
if _new_record.present?
self.attributes = self.class.find(self.id).attributes
else
nil
end
end

private

def before_initialize(options)
Expand Down
8 changes: 6 additions & 2 deletions motion/model/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,12 @@ def save_without_transaction(options = {})
end

# Set created_at and updated_at fields

def set_auto_date_field(field_name)
method = "#{field_name}="
self.send(method, Time.now) if self.respond_to?(method)
if self.respond_to?(method)
self.send(method, Time.now) if self.send(field_name).blank?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this break setting #updated_at on existing records?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I missed this bug because I`m manually setting updated_at on my updater.

end
end

def hooks(name)
Expand Down Expand Up @@ -817,7 +820,8 @@ def unload_relation(col)
end

def initialize_data_columns(column, value) #nodoc
self.attributes = {column => value || self.class.default(column)}
_value = value.nil? ? self.class.default(column) : value
self.attributes = {column => _value}
end

def column_as(col) #nodoc
Expand Down
2 changes: 1 addition & 1 deletion motion_model.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.name = "motion_model"
gem.require_paths = ["lib"]
gem.add_dependency 'bubble-wrap', '1.3.0'
gem.add_dependency 'bubble-wrap', '>= 1.3.0'
gem.add_dependency 'motion-support', '>= 0.2.2'
gem.version = MotionModel::VERSION
end