# What is the best way to put this into models

**URL:** <https://www.ruby-forum.com/t/what-is-the-best-way-to-put-this-into-models/231930>\
**Category:** Rails\
**Created:** [September 7, 2014, 9:15am UTC](https://www.ruby-forum.com/t/what-is-the-best-way-to-put-this-into-models/231930 "2014-09-07T09:15:09Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [September 7, 2014, 9:15am UTC](https://www.ruby-forum.com/t/what-is-the-best-way-to-put-this-into-models/231930/1 "2014-09-07T09:15:09Z")

</div>

Hello,

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.

How can I do this with models ?

Roelof

---

<div class="post-metadata">

**Author:** ![roelof](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@roelof](https://www.ruby-forum.com/u/roelof)\
**Post date:** [September 7, 2014, 11:15am UTC](https://www.ruby-forum.com/t/what-is-the-best-way-to-put-this-into-models/231930/2 "2014-09-07T11:15:22Z")

</div>

On 7 September 2014 08:14, Roelof W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

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

Colin

---

<div class="post-metadata">

**Author:** ![roelof](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@roelof](https://www.ruby-forum.com/u/roelof)\
**Post date:** [September 7, 2014, 1:24pm UTC](https://www.ruby-forum.com/t/what-is-the-best-way-to-put-this-into-models/231930/3 "2014-09-07T13:24:20Z")

</div>

Almost,

I could do that but then how do I store the transactions.  
Another models transactions which points to accounts ?

Roelof

Op zondag 7 september 2014 11:14:40 UTC+2 schreef Colin L.:

---

<div class="post-metadata">

**Author:** ![roelof](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@roelof](https://www.ruby-forum.com/u/roelof)\
**Post date:** [September 7, 2014, 6:08pm UTC](https://www.ruby-forum.com/t/what-is-the-best-way-to-put-this-into-models/231930/4 "2014-09-07T18:08:53Z")

</div>

Transactions could be a model for all the transactions that take place  
on  
accounts.  
Like a payment or a new invoice.

Roelof

Op zondag 7 september 2014 14:25:00 UTC+2 schreef Colin L.:

---

<div class="post-metadata">

**Author:** ![roelof](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@roelof](https://www.ruby-forum.com/u/roelof)\
**Post date:** [September 7, 2014, 6:11pm UTC](https://www.ruby-forum.com/t/what-is-the-best-way-to-put-this-into-models/231930/5 "2014-09-07T18:11:58Z")

</div>

On 7 September 2014 17:07, Roelof W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Transactions could be a model for all the transactions that take place on  
> accounts.  
> Like a payment or a new invoice.

So what is the problem?

Colin

---

<div class="post-metadata">

**Author:** ![roelof](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@roelof](https://www.ruby-forum.com/u/roelof)\
**Post date:** [September 7, 2014, 2:25pm UTC](https://www.ruby-forum.com/t/what-is-the-best-way-to-put-this-into-models/231930/6 "2014-09-07T14:25:24Z")

</div>

On 7 September 2014 12:23, Roelof W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Almost,
> 
> I could do that but then how do I store the transactions.  
> Another models transactions which points to accounts ?

Sorry, I have no idea what you mean. You have not mentioned  
transactions before, is a transaction another model. If so exactly  
what is the problem.

Colin

---

<div class="post-metadata">

**Author:** ![roelof](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@roelof](https://www.ruby-forum.com/u/roelof)\
**Post date:** [September 7, 2014, 8:58pm UTC](https://www.ruby-forum.com/t/what-is-the-best-way-to-put-this-into-models/231930/7 "2014-09-07T20:58:26Z")

</div>

On 7 September 2014 17:42, Roelof W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The problem is if it is the best to put all in seperate models or if there  
> is a better solution ?

All what in separate models?

Colin

---

<div class="post-metadata">

**Author:** ![roelof](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@roelof](https://www.ruby-forum.com/u/roelof)\
**Post date:** [September 7, 2014, 6:44pm UTC](https://www.ruby-forum.com/t/what-is-the-best-way-to-put-this-into-models/231930/8 "2014-09-07T18:44:02Z")

</div>

The problem is if it is the best to put all in seperate models or if  
there  
is a better solution ?

Roelof

Op zondag 7 september 2014 18:11:13 UTC+2 schreef Colin L.:

---

<div class="post-metadata">

**Author:** ![roelof](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@roelof](https://www.ruby-forum.com/u/roelof)\
**Post date:** [September 7, 2014, 10:36pm UTC](https://www.ruby-forum.com/t/what-is-the-best-way-to-put-this-into-models/231930/9 "2014-09-07T22:36:27Z")

</div>

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:

> **[Transaction processing system](https://en.wikipedia.org/wiki/Transaction_processing_system)**
>
> A transaction processing system (TPS) is a software system, or software/hardware combination, that supports transaction processing.   
> The first transaction processing system was SABRE, made by IBM for American Airlines, which became operational in 1964. Designed to process up to 83,000 transactions a day, the system ran on two IBM 7090 computers. SABRE was migrated to IBM System/360 computers in 1972, and became an IBM product first as Airline control Program (ACP) and later as Transaction Pro...

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.

-Jason

---

<div class="post-metadata">

**Author:** ![roelof](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@roelof](https://www.ruby-forum.com/u/roelof)\
**Post date:** [September 8, 2014, 8:34am UTC](https://www.ruby-forum.com/t/what-is-the-best-way-to-put-this-into-models/231930/10 "2014-09-08T08:34:36Z")

</div>

Thanks.

My question was specific to Rails/ActiveRecord.

Roelof

Op zondag 7 september 2014 22:35:45 UTC+2 schreef Jason FB:
