thank you for reading my post. I’ve got s simple question: What’s the
correct technical term for data which IS NOT calculated and data which
IS calculated regarding database design.
Simple example: saving a user message in a corresponding table vs.
counting all messages of a user.
If you also know the german expressions, you’re welcome to post them,
too.
I’m not sure if this answers your question in regards to your specific
example, but let’s say you have a simple table with just two numerical
columns, say two integers.
SELECT i1, i2, i1+i2 AS “Sum” FROM MyTable
will show three columns, two of them real columns from the table and one
computed.
I’m not sure if this answers your question in regards to your specific
example, but let’s say you have a simple table with just two numerical
columns, say two integers.
SELECT i1, i2, i1+i2 AS “Sum” FROM MyTable
will show three columns, two of them real columns from the table and one
computed.
So the term in this case is a COMPUTED column.
The term “derived column” is technically (slightly) more accurate.
ms wrote:
Simple example: saving a user message in a corresponding table vs.
counting all messages of a user.
Saving user messages in a corresponding table.
This would be called a “one-to-many relationship,” or “association” for
short.
Example:
user = User.first
user.messages
Counting all messages of a user.
These types of calculations are called called “aggregate functions.”
Example:
user = User.first
user.messages.count
2a. Caching aggregate functions.
It’s also possible to store the results of aggregate functions in a
column on the parent model. Rails has built-in support for this pattern,
which is called a “counter cache.”
AFAIK Rails support the counter cache only. I’ve occasionally wished it
had direct support for caching “sum” and “average” (avg) aggregate
functions as well, but it can still be doe manually in a similar pattern
as counter cache.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.