On Jan 9, 2:54 am, Jamie Hodge <[email protected]> wrote:
> > Your approach doesn't look bad, but you could try using the
> > nested_attributes plugin.
>
> I looked at nested_attributes. I fail to see how one can add new
> many_to_many associations using the plugins. I see that there are
> _delete/_destroy keys. Where do you intend the what's new?/what's to
> discard logic to sit? I would love to see a gist of an ideal
> many_to_many nesting, or at least the important fragments.

Here's a basic self contained example:

    DB.create_table(:as) do
      primary_key :id
      String :name
    end

    DB.create_table(:bs) do
      primary_key :id
      String :name
    end

    DB.create_table(:as_bs) do
      foreign_key :a_id, :as
      foreign_key :b_id, :bs
      primary_key [:a_id, :b_id]
    end

    class A < Sequel::Model
      plugin :nested_attributes
      many_to_many :bs
      nested_attributes :bs
    end

    class B < Sequel::Model
    end

    a = A.new(:name=>'A')
    a.bs_attributes = [{:name=>'B'}]
    a.save

Basically, if you don't provide a primary key for the nested object,
it creates a new object.  If you provide a primary key, it updates the
existing value unless you provide a _delete or _remove entry, in which
case it deletes or removes it.

Looking at the plugin's documentation, I can see why you would be
confused, it doesn't do a good job of explaining the plugin's use.
I'll try to improve the plugin's documentation before the next
release.

Thanks,
Jeremy

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