I have two models User and Category. Consider the following code
class User < ActiveRecord::Base
accepts_nested_attributes_for :categories, :allow_destroy => true
alias_method :categories=, :categories_attributes=
class Category < ActiveRecord::Base
I want to create categories when it is not already present in the category table. If the category is already present in the table then i need to refer the id of the category to the user in the join table.
And consider i need to add a field say type in the join table along with the reference where i need to add the type of the category.
Say for example
category_id user_id type
1 1 type1
2 1 type2
1 2 type2
1 2 type1
And when getting the category of users i need to get the category object along with the type of the category within the category object.
How can i do this? please help me