Hey,

I've got 2 models: User and Account::Website that look like this:

class User < ActiveRecord::Base
  has_one :website_account, :class_name =>
"Account::Website", :dependent => :destroy
end

class Account::Website < ActiveRecord::Base
  belongs_to :user, :touch => true

  before_validation :assign_new_user, :if => :user_missing?

  protected

  def assign_new_user
    self.user = User.new
  end

  def user_missing?
    user.blank?
  end
end

The problem is with the following code:

website_account = Account::Website.new
website_account.save
website_account.user                          =>  returns persisted
User object
website_account.user.website_account => nil

If I reload the user object, then it correctly returns website
account, but shouldn't it be set automatically by Rails?

Cheers,
Szymon

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to