TOPIC: Stored Dependencies
#899
Stored Dependencies 3 Years, 3 Months ago
It's me again. My new question is about stored dependencies. As I understand (correct me if I wrong), stored dependence is a "signal" for database engine that some field HAS dependencies. Technically it is made with creating the field which name is the same as the first field but with the "_deps" suffix. But what is more? How could database 'knows' which field or fields our field is depended on?

Taking our old 'invoice' and 'invoicelines'. I've slightly modified it and add field 'total price' (i.e. qty * price) in table structure:

Code:

create invoicelines (invoice, line_num, price, product, qty, Total_price)
    index(invoice) in invoice cascade
    key(line_num)



(field total_price is capitalized so it doesn't actually stored in table) and use a rule to calculate it:

Code:

Rule_total_price
function()
    {
    return Number(.qty) * Number(.price)
    } 



It works OK and every time I change the price or qty database engine recalcs total_price (without dependencies at all). But now I want to have a field in header table which summarize the 'total_price' on each line.

I use a query: alter invoice create (Invoice_total_price) and use a rule for it:

Code:

function()
{
return QueryTotal("invoicelines where invoice is " $ String (.invoice_main), "total_price"');
}



That works but partially. Then you browse from record to record, invoice_total_price is calculated OK, but if you are making changes (i.e. add a delete rows, change qty or price), invoice_total_price doesn't reflect it. But if you press Prev, then Next database calculates it again.

So, problem is that Invoice_total_price has no dependencies (it depends on total_price, but Suneido "doesn't know it"). But then I create the stored dependences (alter invoice create (invoice_total_price_deps)) nothing changes.

My questions are:

1) what to do with that dependensies?
2) why total_price rule works without dependensies and invoice_total_price doesn't work?