# Simple Rails ActiveModel Question

**URL:** <https://www.ruby-forum.com/t/simple-rails-activemodel-question/106715>\
**Category:** Rails\
**Created:** [June 13, 2007, 3:34pm UTC](https://www.ruby-forum.com/t/simple-rails-activemodel-question/106715 "2007-06-13T15:34:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjacobs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mjacobs](https://www.ruby-forum.com/u/mjacobs)\
**Post date:** [June 13, 2007, 3:34pm UTC](https://www.ruby-forum.com/t/simple-rails-activemodel-question/106715/1 "2007-06-13T15:34:38Z")

</div>

Hi everyone, I’ll start off with the question and then give the  
backgroud:

When setting up my model, do I want to do all of my generate models at  
the beginning and then fill in the migrations/model scripts all  
referencing each other at the same time? Or should I start with just  
one model at a time and build in the dependencies later? I’m kind of  
confused.

I’m new to rails and have spent many hours with the book “Agile Web  
Development with Rails”, which has been fantastic. I decided to start  
up an example application to see if what I’ve learned so far has really  
‘sunk in’, but I got a little stuck creating my model.

I want to model the situation where a teacher can add meeting  
notes/grades for a student who belongs to a given class in a given year.  
I think I’ll need the following tables:

Years  
Classes (belongs to a year)  
Students (belongs to a class)  
Meetings (belongs to a student)

The reason that years is a table is that some students take the class  
for several years (3-yr program) and we should be able to select one  
particular class from any given year.

Thanks!  
Matt

---

<div class="post-metadata">

**Author:** ![mjacobs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mjacobs](https://www.ruby-forum.com/u/mjacobs)\
**Post date:** [June 13, 2007, 5:28pm UTC](https://www.ruby-forum.com/t/simple-rails-activemodel-question/106715/2 "2007-06-13T17:28:33Z")

</div>

On 6/13/07, Matthew J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> When setting up my model, do I want to do all of my generate models at  
> the beginning and then fill in the migrations/model scripts all  
> referencing each other at the same time? Or should I start with just  
> one model at a time and build in the dependencies later? I’m kind of  
> confused.

It doesn’t matter technically. But the general idea (as you can see  
from the book) is to build the application in iterations, not trying  
to model too far ahead. Things tend to change as you get into it. But  
it helps to think about the “big picture”, which is what you’re trying  
to do here.

> for several years (3-yr program) and we should be able to select one  
> particular class from any given year.

I think you might need more models. For example, you might have a Year  
and a Class (probably should change that to “Course”, since “class” is  
a Ruby keyword). Example:

Year = 2007-08 academic year  
Course = Basket Weaving

There’s probably a many-to-many relationship between those; any given  
year can have many courses, and any given course could be offered in  
multiple years. So you would use another model to represent that. What  
would you call it? I don’t know what to call it, so I’ll call it  
“Offering”

So:

Year → has\_many → Offering  
Course → has\_many → Offering

Now you have Student. This would information about a given student.  
Now look at the relation between Student and Offerings. Any given  
student could be enrolled in multiple offerings, and any given  
offering would have multiple students. Again, you would use another  
model to represent the relationship (because it’s many to many). Let’s  
call it Enrollment.

So:

Offering → has\_many → Enrollment  
Student → has\_many → Enrollment

Where would a Meeting go? I think it would belong to Enrollment. If a  
meeting represents a given student meeting with the teacher of a  
specific course for a specific term, then Enrollment represents that.

So:

Enrollment → has\_many → Meeting

Just some ideas. Worth what you paid for them :~)
