No, because belongs_to is for when the foreign key lives on the record with the association and has_one is when the foreign key lives on the associated model instead.
Ypu can't have the _id setter on the model with the association because there is no such field on the model or underlying table. On Friday, September 29, 2017, Shishir Kakaraddi <shishirkakara...@gmail.com> wrote: > has_one relationships don't have id only getters or setters. For example > engineer.laptop_id or engineer.laptop_id= are not implemented in Rails 5. > Is there any reason for this? > > class Engineer < ActiveRecord::Base > belongs_to :team > has_one :laptop > has_many :tasks > end > > > engineer = Engineer.first > > > # Getters > engineer.team_id # works > engineer.laptop_id # doesnt work (Not implemented) > engineer.task_ids # work > > > # Same issue with setters too. > > Thanks > Shishir > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-core+unsubscr...@googlegroups.com > <javascript:_e(%7B%7D,'cvml','rubyonrails-core%2bunsubscr...@googlegroups.com');> > . > To post to this group, send email to rubyonrails-core@googlegroups.com > <javascript:_e(%7B%7D,'cvml','rubyonrails-core@googlegroups.com');>. > Visit this group at https://groups.google.com/group/rubyonrails-core. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at https://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.