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:
- 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.
- 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.
- 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.