I try to make a financial app.
Now I have this problem.
I have customers which are put into a model.
What I want is if I made a customer also a financial account is made
with a
specific number.
So customer 1 has account number 16001.
If the customer buys anything a invoice is made and must be put into the
right 1600x number.
If the customer buys anything a invoice is made and must be put into the
right 1600x number.
How can I do this with models ?
Not sure what question you are asking. Is it what should the models
and relationships be? If so then possibly something like
customer has_one account
account belongs_to customer
and account has a field account_number (which will contain 16001 in
the above case).
FWIW, we’re not entirely sure if you’re asking specifically about data
modeling (like a general CS question) or a question specific to
Rails/ActiveRecord. You probably would do yourself well to get advice
about your system from someone with computer science experience,
specifically building transactional systems.
Generally speaking from my own experience with transactional systems,
ActiveRecord has some drawbacks that don’t optimize for scale. In
particular, if the set of operations requires lots and lots of objects
to be loaded during any given transaction, ActiveRecord has a high cost
(slow) associated with object instantiation. This doesn’t affect most
Rails apps if they create 25-50 objects in the lifecycle of any given
request, but when a request is going to create hundreds and hundreds of
objects you’re going to see some bottlenecks at scale. (I’m not sure if
this really applies to you – just some background as you are going down
this path.)
This doesn’t mean that Rails is the wrong solution – it just means you
have to think about the bigger picture and perhaps know a little more
about architecture than you do right now. Other alternatives to
ActiveRecord (Datamapper) do not have as high a cost of object
instantiation so might be good options for a problem like this.
There are yet other advanced design patterns for transactions and
banking systems too – for example, just check out all the discussion
about things other people have solved before you on the “Transactional
processing system” Wikipedia page:
All of those concerns are out of the scope of Rails & ActiveRecord.
If I were you I’d learn a little more about your domain problem and back
up and research different options, then prototype some in Rails and see
if you measure how fast common operations take.