There seems to be a general sense in the Rails community that habtm
associations are deprecated for more complex models
http://dev.rubyonrails.org/changeset/4123

In terms of creating a cleaner interface it seems that a good strategy
is to use a cascaded has_many : though, on top of an ordinary has_many
association for the models on each side of the relationship (i.e.. A
and B as: A->AB<-B) to the middle relationship model (i.e. as before
AB) which in turn has belong_to association back to each side
model.

To add additional context: Then to access the additional attributes on
the relationship model, one can use the acts_as_proxy plug-in to
expose these attributes on each side model class.
Note: Obviously the proxies value on the start side of the
relationship is of limited value as only the value for the first
associated record is returned, any view logic will use the proxies
values on the other side of the relationship

This all being the case you'd have two model classes and a
relationship model class as follows:

class A < ActiveRecord:base
  has_many :a_bs
  has_many :bs, :through => :a_bs

  proxies :a_bs, :shared # where the a_bs.shared column is
instantiated as :a_b_shared
end

class AB < ActiveRecord:base
  belongs_to :a
  belongs_to :b

  # AB has a column called :shared

end

class B < ActiveRecord:base
  has_many :a_bs
  has_many :as, :through => :a_bs

  proxies :a_bs, :shared # where the a_bs.shared column is
instantiated as :a_b_shared
end

Then you have a controller for A and B:

class AsController < ApplicationController
  active_scaffold :a do |config|
    config.nested.add_link("Links", [:bs])
    config.nested.shallow_delete = true
  end
end

class BsController < ApplicationController
  active_scaffold :a do |config|
    config.nested.add_link("Links", [:as])
    config.nested.shallow_delete = true
  end
end

Is seems that AS does not seem to support Many to Many in this form,
or do I have a configuration issue ? I have seen other similar issues
with no responses.

In looking at the code it seem that the is_habtm? condition in
nested.rb would need to be expanded to add the Add/Remove Existing
functionality. I rigged this code a little to experiment but the code
blows up when adding constraints once the "Add Existing" action is
initiated. Specifically in association_proxy.rb:148 with a
NoMethodError (undefined method 'a=' for []:Array)

I attempted to add a new issues on this 
http://code.google.com/p/activescaffold/issues/detail?id=679
but have been directed to open a discussion first.

Additionally as an aside I'd be looking at using this approach with
the nested_has_many_though plug-in too.

Any information and help greatly appreciated.

Thanks
-Simon

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