Make has_one building syntax to look the same as for has_many

15 views
Skip to first unread message

Alex Galushka

unread,
Apr 8, 2016, 5:09:15 PM4/8/16
to Ruby on Rails: Core
class User
  has_many
:tips
  has_one
:photo
end

user
.tips.build(params)
user
.photo.build(params)

Currently we have to use different syntax user.build_photo because user.photo can return nil. We can return some kind EmptyRecord instance the support the same methods that we have for has_many

user.photo.build
user
.photo.create
user
.photo.create!


Reply all
Reply to author
Forward
0 new messages