> In that case, I'd do:
>
> def modified?
> super || @imgs
> end
>
> Actually, maybe there should be a Model#modified! method that modified
> considers, usable like:
>
> def pictures=(imgs)
> �...@imgs = imgs
> modified!
> end
>
> If you call modified!, the record is considered modified until the
> next time it is saved (so update and save_changes will attempt to save
> the record). Do you think that would make sense?
I originally thought up a similar solution, but realized that it, like
your proposed solution, always did an UPDATE of the row, even if
columns of the row did not change. I don't think there's a good way to
go about this except for the change the happen in Sequel's
implementation of hooks. I know you think the change would require
overturning a lot of the current implementation, but that's the amount
of work it would take to override the current behavior in a subclass.
I think it would be best for Sequel to correct the behavior in the
following way:
class Model
def update_restricted(*args)
transaction(use_transactions) do
before_update_or_raise
set_restricted *args
result = save
after_update_or_raise
result
end
end
def save(*columns)
opts = columns.last.is_a?(Hash) ? columns.pop : {}
columns = nil if columns.empty?
transaction(opts.include?(:transaction) ? opts[:transaction] :
use_transactions) do
before_save_or_raise
result = if new?
insert_row(columns)
else
if options[:changed]
columns = columns && (columns & changed_columns) ||
changed_columns
update_row(columns)
else
update_row(columns)
end
end
if columns
changed_columns.reject! {|c| columns.include? c}
else
changed_columns.clear
end
after_save_or_raise
end
self
end
def update_row(only_columns = nil)
if only_columns
... # update only only_columns
else
... # update all columns
end
end
end
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---