ruby on rails - Design a Book model with several editions in a database -



ruby on rails - Design a Book model with several editions in a database -

i have textbook model , i'd have several editions of same textbook (allowing each edition have different title, price, etc) , able retrieve editions particular textbook. how design relation?

my thought create first instance of book root book , associate subsequent book editions it. , if delete root book, example, arbitrary root should chosen automatically existing editions.

i've looked @ ancestry gem, looks overkill given tree have maximum depth 1. again, i'm not sure tree construction right solution.

in real world, books messy.

i'm not sure i've ever seen multiple editions of 1 book had different titles, guess there's no law against that. if can happen, need think along lines of set of editions beingness arbitrary collection of titles.

let's start this. imagine titles might different different editions, although aren't actual book. (larson's calculus , spivak's calculus.)

title isbn cost edition -- calculus 128505709-0 $235.34 10 calculus 128509108-6 $ 86.50 10 calculus 054716702-4 $290.65 9 calculus 061850298-x $ 67.96 8 calculus 039586974-9 $ 56.99 6 calculus 091409891-8 $ 80.75 4

we can't select set of editions title, because we're letting titles vary among editions, , because same title can written different authors. (the first 5 above larson's calculus; lastly 1 spivak's calculus, different textbook.) 1 edition can published different publishers, in case title, authors (not shown), , edition same, , isbn different. (often, title's hardback , paperback published different publishers.)

all means need table.

edition name isbn -- larson's calculus 128505709-0 larson's calculus 128509108-6 larson's calculus 054716702-4 larson's calculus 061850298-x larson's calculus 039586974-9 spivak's calculus 091409891-8

on 1 hand, seems clear need info set of editions. bring together on isbn. in rails, of course, you'll using id numbers throughout.

the edition name could title, we're letting titles vary among editions of 1 book. picking title might cause more problems solves.

so don't think need gem handle this. 1 more model , right associations.

ruby-on-rails ruby-on-rails-3 activerecord database-design relational-database

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -