Rails Database Design for Multiple Associated Record Types -


this design question. hope acceptable here.

back in days of yore, worked on accounting system used flat files store records in proprietary format. transaction 'table' stored multiple types of transactions in format of fixed header (which held transaction type amongst other things) , detail record varied according transaction type.

we did in c using structs , unions manage records.

once again find myself working on finance system, time i'm doing in rails postgresql target database.

i'm considering design of transaction system in new project , i'm wondering how in best, rails way.

  • do have multiple tables, 1 each transaction type: journals, sales, purchases, etc? (does violate dry?)

  • or, have single transaction table represents header, , multiple tables detail of each type?

    if way, how associations work? can association use single id connection multiple tables?

  • or, have single, un-normalized record every possible field complete range of transaction types?

  • or... possible overload table record in way did many years ago?

(not keen way though.)

any ideas have on appreciated.

option 1 sounds you'd need polymorphic association, supported rails out of box. although works other way around - usual use-case along lines of comment object can belong multiple content types. there's gist here may or may not help: gist.github.com/runemadsen/1242485

although gist uses join table on can add common fields, starts sound multiple table inheritance, second choice. solution. you'll need gem make work rails though. try one:

github.com/hzamani/active_record-acts_as

option 3 sounds single table inheritance bad move.

i'm not sure how 4 differs 2.

i err on side of 2: multiple table inheritance. granted, if polymorphic association works it's nice using rails native features, think you'd find more , more annoying deal on time. simple things counting transactions or getting transactions within date range become arduous , fragile. mti pattern created kind of situation.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -