I'm having a strange issue with acts_as_relation. I have my (simplified) models structure as follows:
class User < ActiveRecord::Base
has_one :occupation
end
class Occupation < ActiveRecord::Base
acts_as_superclass
belongs_to :user
validates :user_id, presence: true
end
class Worker < ActiveRecord::Base
acts_as :occupation, as: :occupation
end
In my migration, I used
create_table "occupations", force: true do |t|
t.integer "occupation_id"
t.string "occupation_type"
t.integer "user_id"
end
With this hierarchy (very similar to bigardone's one), I was expecting to be able to do the following simple assignment
I realised that you don't actually say this is possible anywhere in the docs, but I thought it would be. Currently, I'm working around this as follows:
user.occupation = Worker.new.occupation
which feels a bit like a hack.
I understand this is a very basic question, but I am relatively new to Rails, so I am wondering if I'm missing something?
I'm having a strange issue with acts_as_relation. I have my (simplified) models structure as follows:
In my migration, I used
With this hierarchy (very similar to bigardone's one), I was expecting to be able to do the following simple assignment
however I'm getting this error:
I realised that you don't actually say this is possible anywhere in the docs, but I thought it would be. Currently, I'm working around this as follows:
which feels a bit like a hack.
I understand this is a very basic question, but I am relatively new to Rails, so I am wondering if I'm missing something?