The reason why the avatar column is assigned only on `before_save` is because that's when the uploading happens. And when the uploader does its uploading on whatever store (file system, s3 or other), it returns the file ID, which then gets saved to the column. So it can only be assigned during saving, not before.
On Tue, Mar 17, 2015 at 1:36 PM Janko Marohnić <[email protected]> wrote: > Hello Jeremy, > > I'm trying to integrate Sequel with Refile > <https://github.com/refile/refile>. How it Refile integrates with a model > is similar to other uploading solutions, with callbacks/hooks. There is > already an ActiveRecord integration > <https://github.com/refile/refile/blob/master/lib/refile/attachment/active_record.rb>, > and I'm trying to make Sequel's one similar. > > However, there is one key difference between ActiveRecord and Sequel when > triggering of hooks. ActiveRecord *always* saves the record (thus trigger > the before_save callback), even when no columns change. Sequel triggers the > before_save only when columns change (or it's a new record). Is it possible > to make Sequel always save? It would be great to have it as a per-model > setting. > > I'm currently doing it in a way that I'm overriding `avatar=`, > `remove_avatar=` and `avatar_remote_url=`, and calling `will_change_column` > to trigger the change (becuase on `before_save` the column does get > changed). But I don't like this approach, I have to tie too tightly to > Refile's implementation. > > Sincerely, > Janko > > > > -- > You received this message because you are subscribed to a topic in the > Google Groups "sequel-talk" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/sequel-talk/uSEoYlI8xfg/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/sequel-talk. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
