Just adding some more detail about how to reproduce:

1. Create a Product (p1), with no associated products.
2. Create a second Product (p2), with no associated products
3. Create a third Product (p3), with two associates - p1 and p2
3. Edit p3 and remove p2 as an associate -> Correctly removes p2 as an
associate
4. Edit p3 and remove p1 as an associate -> Does not remove p1 as an
associate
5. Edit p3 and add p2 as a second associate -> Correctly adds p2
6. Edit p3 and remove both p1 and p2 associates -> Does not remove
either associate


On Apr 7, 3:59 pm, anton <[email protected]> wrote:
> Hi,
>
> Hoping someone can help me with this. I have a :has_many :through self
> referential association. Creating/Adding/Removing Products and nested
> associated products in working fine apart from when you try to remove
> the last existing Product of the association. The update isn't
> triggered on the association table (I'm presuming because there is no
> collection in the updated model to trigger the associated update/
> delete).
>
> See example below, where a Product can have many AssociatedProducts:
>
> Tables:
> create_table :products do |t|
>       t.string      :title,             :null => false
> end
>
> create_table :associated_products do |t|
>       t.references :product, :null => false
>       t.integer :associated_id, :null => false
> end
>
> Models:
> class Product < ActiveRecord::Base
>   has_many :associated_products, :dependent => :destroy
>   has_many :associates, :through => :associated_products
> end
>
> class AssociatedProduct < ActiveRecord::Base
>   belongs_to :product
>   belongs_to :associate, :class_name => "Product", :foreign_key
> => :associated_id
> end
>
> Controllers:
> class ProductsController < ApplicationController
>   active_scaffold :product do |config|
>     config.columns = [ :title, :associates ]
>     config.columns[:associates].form_ui = :select
>     # Same behaviour whether draggable_lists or standard checkboxes
> are used
>     #config.columns[:associates].options = {:draggable_lists => true}
>     config.columns[:associates].label = "Associated Products"
>   end
> end
>
> Any help on this greatly appreciated.
>
> Cheers,
>
> Anton

-- 
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" 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/activescaffold?hl=en.

Reply via email to