I hate to go overboard on this question but I think a lot can be learned 
here.

Your question dives into several sub-topics at once (database 
normalization, model associations, and ERD structures).  I would 
concentrate on the following first:

1.  Use a good diagramming ERD software (RISE is a good free one)

This will help you create a visual diagram of your models and help you 
better define and establish relationships with them.

2.  Database normalization.

It's important to keep your database normalized but there are instances 
where you can go too far and create a very unwieldy structure.  Read up 
on normalization and get a solid grasp on it before you get too deep in 
your project.

3.  Model Associations

Once you have done the above, I'd ask a few questions.

First, let's talk about books in general and what is common about them.

Books have titles (they can also have duplicate titles)
Books have authors (single or multiple)
Books have identification numbers
Books have many editions
Books can be hardback or paperback or electronic
Books have value
Books have conditions (age, wear, signed/unsigned, etc.)

Second, as far as looking at a book as a simple object, what pieces 
should really go in the book model?  While that's solely up to you I 
would drive the following:

Book Model

has_many :conditions

title:string
authors:text (you can serialize the field as JSON to store a hash)
identification:string
edition:string
published_date:date
hardback:boolean
paperback:boolean

It would be difficult to use ISBN as an ident on every book since it has 
only been uniquely assigned since 1970.

Condition Model

belongs_to :book

book_id:integer
age:integer
signed:boolean
torn:boolean
pages_missing:boolean
marked:boolean
pristine:boolean

Even though books have a published date, the edition might change the 
age of the book.

I hope this example helps.

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/672babe344c5eb857f74450ffd7481fa%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to