# First Model - Please assist

**URL:** <https://www.ruby-forum.com/t/first-model-please-assist/146062>\
**Category:** Rails\
**Created:** [August 17, 2008, 2:19am UTC](https://www.ruby-forum.com/t/first-model-please-assist/146062 "2008-08-17T02:19:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![trope](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71c47a/32.png) [@trope](https://www.ruby-forum.com/u/trope)\
**Post date:** [August 17, 2008, 2:19am UTC](https://www.ruby-forum.com/t/first-model-please-assist/146062/1 "2008-08-17T02:19:39Z")

</div>

Hi. I am new to RoR. I am beginning my first app. It’s a simple  
application for roofing contractors.

I want to start slow. I can “migrate” as I go, correct?? (smile)

So Far I have Three Models:

CUSTOMERS , JOBS, ESTIMATES

there will be more someday.

## So far, the model should adhere to these simple rules:

1. You can enter a customer without it being a JOB or ESTIMATE.

2. You can CONVERT a customer to a JOB.

3. You can CONVERT an ESTIMATE to a JOB.

4. A JOB MUST have a customer.

5. An ESTIMATE MUST have a customer.

6. CUSTOMER can have MANY jobs.

7. CUSTOMER can have MANY ESTIMATES.

8. Once converted from ESTIMATE to JOB , removed from ESTIMATE.

* * *

Holy cow… did I bite off more than I can chew here??? At first  
this seemed rather simple until I just typed it all out!

Ok, I don’t have ANY code so far. Watched TONS of screencasts,  
purchased a few, books, etc. I think (thought) I was ready. Here  
goes… Please be gentle…

* * *

CUSTOMER MODEL:

* * *

class Customer\< ActiveRecord::Base  
has\_many: estimates  
has\_many: jobs  
end

* * *

ESTIMATE MODEL:

* * *

class Estimate\< ActiveRecord::Base  
belongs\_to : customer  
end

* * *

JOB MODEL:

* * *

class Job\< ActiveRecord::Base  
belongs\_to : customer  
end

Is it that simple?? Does my above code adhere to all my rules ( or  
SOME anyways? ).

Thanks! Again, first application.

Regards,

Giovanni

---

<div class="post-metadata">

**Author:** ![trope](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71c47a/32.png) [@trope](https://www.ruby-forum.com/u/trope)\
**Post date:** [August 17, 2008, 3:09am UTC](https://www.ruby-forum.com/t/first-model-please-assist/146062/2 "2008-08-17T03:09:56Z")

</div>

On 17 Aug 2008, at 01:18, trope wrote:

> 1. A JOB MUST have a customer.
> 
> 2. An ESTIMATE MUST have a customer.
> 
> 3. CUSTOMER can have MANY jobs.
> 
> 4. CUSTOMER can have MANY ESTIMATES.
> 
> 5. Once converted from ESTIMATE to JOB , removed from ESTIMATE.

This sounds reasonable - as do your models. As things stand your rules  
abut jobs having to have an associated customer will not be enforced.  
I usually use a foreign key constraint for that sort of thing.  
One suggestion though: don’t delete estimates when they turn into a job.  
I don’t know much about the sector in which you’re doing business, but  
an audit trail is often valuable. If you do that then you probably  
want job to belong\_to estimate( in addition to what you’ve already got).

Fred
