On the application I'm currently working on, I'm stuck on setting up the associations between 3 models to ensure referential integrity. I have an Event model, Building model, and a Room model. The association in real life is pretty intuitive. An Event can only be in one Building and one Room. A Building clearly can have multiple rooms.

Here's what I have set up now. However, how can Events specify their room if they belong to Buildings, and the foreign key for the Room is in the Events table? Is this where you use a has\_many :through relationship? Is it good practice to store both the Building and Room foreign keys in the Event table, as Rooms are owned by Buildings? What about the conditional relationship that requires a building to be specified before allowing a room to be specified (some buildings have 2 rooms, others have 20, for example)

Sorry I'm so unclear on this. Thanks in advance for the help!

```
    class Event < ActiveRecord::Base
    belongs_to :building

    end

    class Building < ActiveRecord::Base
    has_many :events
    has_many :rooms

    end

    class Room < ActiveRecord::Base
    belongs_to :building

    end

```