Forum: Ruby on Rails optional has_one association

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Guest (Guest)
on 2006-03-23 16:59

I have a has_one association which is used for extending an entity,

class User < ActiveRecord::Base
  has_one :user_ex

  #name, email

class UserEx < ...
  #country, city, street...

The UserEx entity is optional (there are users without extended info).
My problem is: if u is a User object which has no user_ex extension,
activerecord always tries to fetch the UserEx object whenever I
write u.user_ex (it thinks user_ex isn't yet loaded). I also want to
include the user_ex association when I load some users. What is
the simplest way to do this?

This topic is locked and can not be replied to.