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