# Model inheritance

**URL:** <https://www.ruby-forum.com/t/model-inheritance/160653>\
**Category:** Rails\
**Created:** [February 18, 2009, 2:41pm UTC](https://www.ruby-forum.com/t/model-inheritance/160653 "2009-02-18T14:41:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [February 18, 2009, 2:41pm UTC](https://www.ruby-forum.com/t/model-inheritance/160653/1 "2009-02-18T14:41:03Z")

</div>

Hi all,

When I have  
class User  
:has\_many :events  
end

class Event  
:belongs\_to :user  
end

class Game \< Event  
end

Why Can’t I do:  
user = User.find(1)  
user.games.build(params[:game])

I need to add to  
class Game \< Event  
:belongs\_to :user  
end  
and  
class User  
:has\_many :events  
:has\_many :users  
end

then  
user = User.find(1)  
user.games.build(params[:game])  
will work.

Since Event already belongs\_to user shoiuld game than also since it  
inherites?

Regards,  
Stijn

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [February 18, 2009, 2:46pm UTC](https://www.ruby-forum.com/t/model-inheritance/160653/2 "2009-02-18T14:46:23Z")

</div>

On 18 Feb 2009, at 13:40, Tarscher wrote:

> class User  
> :has\_many :events  
> :has\_many :users

I assume you meant to write has\_many :games 🙂

You can’t do user.games.build without this since there is no games  
association, only an events association. You shouldn’t need the extra  
belongs\_to :user (which as you say should just be inherited from Event)

Fred

>
