Hi everyone,
I ran into some problems when modeling mailbox and mails. My code was like:
create_table :mailbox do |t| t.integer :user_id # the owner of this mailbox end
create_table :mails do |t| t.integer :sender_id t.integer :receiver_id t.string :title t.text :content end
class Mailbox < ActiveRecord::Base belongs_to :user
has_many :sent_mails, :class_name => 'mail', :conditions => { :sender_id => self.user_id } # I know this is wrong
has_many :recv_mails, :class_name => 'mail', :conditions => { :receiver_id => self.user_id } end
I know this is wrong. because user_id is an instance method and self refers to the class object. My question is how to fix this problem?
Thanks in advance Xiahong