Optional has_one association

Hi!

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

class User < ActiveRecord::Base
has_one :user_ex

#name, email
end

class UserEx < …
#country, city, street…
end

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?

Thanks,
Adam

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs