Forums

Issues CC/CF Multiplier

sebafouss 05 Jan, 2016
Hi,

I have the following setup in my SQL DB:
- 1 table (buildings)
- 1 table (meters)
with an 1:n association between them (1 building can have multiple meters).

On CF side, I have one form detailed all the fields from "buildings" table + 1 multiplier for "meters" tables.

I also display a summary page listing all the buildings in a table; for this purpose I use CC. CC list all the buildings (1 building per line), and 2 buttons per line: edit (opens CC form) and delete. CC form has one model: "buildings".

With this setup, I have 4 questions/issues:

1) I would like to display, in the CC buildings summary page, the number of meters per building (ie in each line, next to building information retrieved from buildings table, a cell displaying the number of meters for this building). I have no clue how to proceed. I tried to add a second model in CC for "meters", but after that I don't know how to proceed.

2) In CC page, when I click the delete button, the building entry is deleted but the associated meters are not. Again, no idea how to proceed here.

3) Noticed something strange in the multiplier: if I create a new building and add meters, these meters will receive a uniq_id in their SQL table. However, if I edit an existing building and add some meters, these new meters will have an empty uniq_id field.

Thanks for any help🙂
GreyHead 05 Jan, 2016
HI sebafouss,

1. If you turn on the CC Debugger you should be able to see the data that is being loaded for each row. I imagine that you will need to process the meters data somehow if you just want a total displayed. You might be able to do that using SUM in the query, or using an entry in the PHP box to sum after the data is loaded.

2. The built-in CC Delete function is pretty basic and I don't think that it can handle linked tables. You can change this button to link to a form event and pass the record ID, then in the event add Custom Code to delete all the records (or possibly better - mark them as deleted so that the process can be reversed if necessary).

3. Unless you are using the uniq_id you can probably just ignore this.

Bob
sebafouss 05 Jan, 2016
Thanks Bob.

One point is not clear to me regarding the first question: how can I use a SUM in the query ? More precisely, how can I modify this query ? I understand that the query is created automatically by CC.

Thanks,
GreyHead 05 Jan, 2016
Answer
1 Likes
Hi sebafouss,

I'm not completely clear either but we have worked out that putting this in the Fields box on the Models tab of the listing seems to work
<?php return array("COUNT(id)" => "content.num"); ?>
so I think that the same method is worth trying with SUM

Bob
sebafouss 06 Jan, 2016
Hi Bob,

Thanks, I have been able to manage my issues.
This topic is locked and no more replies can be posted.