has_many relationship also has the foreign key in another table in the 
above example it would be in the tasks table. Regardless it has an accessor 
only for ids of related tasks engineer.task_ids.

Similarly, Shouldn't has_one also have accessors for id even if its in 
another table?


On Saturday, September 30, 2017 at 6:50:49 AM UTC-7, Colin Law wrote:
>
> That is because there is no laptop_id in Engineer (assuming engineer 
> has_one laptop). Laptop has an engineer_id. You can do 
> engineer.laptop.id 
>
> Colin 
>
> On 30 September 2017 at 01:10, Shishir Kakaraddi 
> <shishirk...@gmail.com <javascript:>> 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-co...@googlegroups.com <javascript:>. 
> > To post to this group, send email to rubyonra...@googlegroups.com 
> <javascript:>. 
> > 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.

Reply via email to