Ok, my idiotic mistake, thank you. I am persisting the tags now using
this code:

    def after_save
      tag!
      super
    end

    def tags= tags
      @tag_names = tags.split(',').map{ |name| name.strip.titleize }
    end

    def tag!
      return unless tag_names
      existing_tags  = Tag.where(:name => tag_names).all
      tags_to_create = tag_names - existing_tags.map(&:name)

      Tag.multi_insert tags_to_create.map{ |name| {:name => name} }
      remove_all_tags
      DB[:causes_tags].multi_insert tag_names.map{ |name| {:tag_name
=> name, :cause_id => id} }
    rescue Sequel::DatabaseError => e
      tag!
    end




On Jan 12, 8:00 pm, Jeremy Evans <[email protected]> wrote:
> On Jan 12, 5:45 pm, Macario Ortega <[email protected]> wrote:
>
> > Hi, I wan't to do something with a model after it has been saved, i.e.
> > associate it with a list of tags after the model is saved but by then
> > I loose my instance variables, this is the only non obvious for me
> > behavior I found so far with sequel, I would not expect this to
> > happen.
>
> >   class Cause < Sequel::Model
> >     many_to_many  :tags, :right_key => :tag_name
>
> >     def tags= tags
> >       @tag_names = tags.split(',').map(&:strip)
> >     end
>
> >     def after_update
> >       @tag_names # => nil
> >       super
> >     end
> >   end
>
> Are you calling tags= on the same model instance before calling save/
> update?  If not, that's probably the issue.  Also, you don't appear to
> be persisting the tags, which raises a red flag to me.
>
> Jeremy
>
> > So the way for associating on creation would be outside the model?
>
> > Thanks

-- 
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.

Reply via email to