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
--~--~---------~--~----~------------~-------~--~----~
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-talk@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