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
<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.
> 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.

-- 
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