First Model - Please assist

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs