php - CakePHP mathematic-calculation field? -


(like database structure)

So, in Cake PHP, I have two tables: trees, And leaves Each leaf has tree_id for its related tree, each leaf has a numerical value for the tree, the default view of the baked tree, lists all the trees in just one table. Is there a way to add a dynamic column to the table of that view that makes all the leaves of the tree SUMS and displays the totals in the table, as well as a tree in another area What does the number represent?

Example:

Address

  id | Tree ID | Leaf Price ----- + ----------- + ---------------- 24 | 1 | 19 70 | 1 | 33 121. 1 | 30  

tree

  id | Tree | Number of Leafs | Yoga of Leaf | Verb----- + -------- + ------------------- + -------------- - + ------------------- 1 | Foo | 120 | 7270 | Edit Delete 2 | Bar 72 | 4028 | Edit View  

Two thoughts:

Get the summary field Dynamically every time you need to use it (from the top of my head):

  $ this-> Tree-> Search ('All', array (... 'array (' Leaf.tree_id ')))' = & gt; Array ('address' = & gt; array ('field' = & gt; array ('SUM (leaf.value)'), 'group' = & gt;;  

or Create a new column in the tree model such as leaf_values ​​ and update every time you change something in the Leaf Model:

  After the shift Feel Modal Function () ($ sum = / * calculate sum * /; $ this-> Tree-> UpdateAll (array ('tree. leaf_values' = & gt; $ sum), array ('  
tree.id => $ this-> data ['leaf'] ['tree_id']));} delete after the function ()

Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -