# Mailbox model

**URL:** <https://www.ruby-forum.com/t/mailbox-model/172007>\
**Category:** Rails\
**Created:** [July 13, 2009, 11:12am UTC](https://www.ruby-forum.com/t/mailbox-model/172007 "2009-07-13T11:12:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xiahong\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/3d9bf3/32.png) [@Xiahong\_G](https://www.ruby-forum.com/u/Xiahong_G)\
**Post date:** [July 13, 2009, 11:12am UTC](https://www.ruby-forum.com/t/mailbox-model/172007/1 "2009-07-13T11:12:03Z")

</div>

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
