views:

20

answers:

1

Hi, I have the next models:

create_table :categories do |t|
  t.integer :category_id
  t.integer :language_id
  t.timestamps
end

create_table :category_localizated_categories, :force => true do |t|
  t.column :category_id, :integer
  t.column :localizated_category_id, :integer
end

class Category < ActiveRecord::Base
  has_many :category_localizated_categories
  has_many :localizated_categories, :through => :category_localizated_categories
end

class CategoryLocalizatedCategory < ActiveRecord::Base
   belongs_to :category
   belongs_to :localizated_category
end

I can do:

category1 = Category.create :language_id => 1
category2 = category1.localizated_categories.create :language_id => 2

And 2 categories are created in DB, but the association is not created:

category.localizated_categories
[]

What could be the problem? Thanks.

A: 
class Category < ActiveRecord::Base
  has_many :category_localizated_categories
  has_many :localizated_categories, :through => :category_localizated_categories
  accepts_nested_attributes_for :category_localizated_categories
end

i think you need nested models here:

http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes

corroded
But I can't even do: category1.localizated_categories << category2, it doesn't creates the association neither.
fjyaniez