association problems, :belongs_to and :has_many

Perhaps something like this works: http://pastie.caboo.se/58534

It's pretty dirty though..

Raj,

In addition to anything else that you do, you may want to change the
column name from “type” to something else. This may be effecting it
since the type column has a special purpose in AR and shouldn’t be used
except for STI.

One option for removing the duplicates would be to specify a distintct call on the db.

has_many :products, :select => “SELECT DISTINCT * FROM”

Cheers

Daniel

Raj,

I’m having a little trouble trying to visualise your data
structure. Do you think you could post the minimal relevant
class declerations with the associtation declerations included.

Cheers

Removing the duplicates in this instance should be as easy as changing
the HABTM declerations in your kind and section models by setting the
:uniq option to true. Any duplicates should then be ignored.

class Kind < ActiveRecord::Base

has_and_belongs_to_many :sections, :uniq => true

end

and

class Section < ActiveRecord::Base

has_and_belongs_to_many :kinds

end

Hopefully I’ve understood the issue there :wink:

Cheers

Sorry a bit hasty with the go button.

You will need to add the :uniq => true option to both kind and section class HABTM’s

I’m sorry my head might be packed with cotton this morning, but I’m really not understanding what your trying to do.

It seems that the joining logic your trying to put into these
controllers should exist in the models since they are related to your
data integrity. You would probably be better off using has_many
:through instead of HABTM because you can put your join logic into
these fully blown rich join models. Adding joining logic to habtm
is messy because you need to put it all over the place. By
including it into the join model it keeps all the joining logic
dry. You can also use the :uniq try option where you need it to.

Hope that helps

Daniel