Model inheritance

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

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 :slight_smile:

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