I think it makes sense. Note that there are a whole other methods that exist on `has_many` relations that do not have equivalent on `has_one`:
- clear - empty? - size - etc (see: http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_many vs http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_one) But I think this is intentional... `has_one` associations are tricky and hard to "fit" into a novices mindset. Having getters like `.association_id` would only make things more complicated when the programmer bangs their heads against the wall because `.association_id = 123`. On Saturday, September 30, 2017 at 12:29:23 PM UTC-3, Shishir Kakaraddi wrote: > > 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> 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. >> > To post to this group, send email to rubyonra...@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.