ruby on rails - Lost the last object assigned using rails_admin -
i'm using rails_admin have crud functionality on models. have 2 models category , project. project
can have 1 category
1 category
can in many project
s. problem when created 2 different project
s same category
previous 1 lost relation, last 1 created keep it. how can create different project
s same category
.
my models are:
category
class category < activerecord::base belongs_to :project, :inverse_of => :category end
project
class project < activerecord::base has_one :category, :dependent => :destroy, :inverse_of => :project def category_id self.category.try :id end def category_id=(id) self.category = category.find_by_id(id) end end
the relationships seeking of are:
- project
belongs_to
category - category
has_many
projects
the belongs_to
relationship declared category in model file says each category object can bind 1 project object.
have @ http://guides.rubyonrails.org/association_basics.html#choosing-between-belongs-to-and-has-one find out more 2 relationships using.
Comments
Post a Comment