Related Records

4 posts by 2 authors in: Forums > CMS Builder
Last Post: May 9, 2014   (RSS)

By Toledoh - April 29, 2014

Hi Guys,

I have a table of "individuals", and within that table I have a relatedRecords field called "notes" that allows me to view and create notes on that person with "individual ='<?php echo mysql_escape(@$RECORD['num']) ?>'"

However, when I create a new record, and that record has not been saved as yet, this relatedRecords field shows a bunch of notes - I guess because that current record in NULL and it's displaying all notes that have no individual associated to them.

Is there any way to not show all those notes unless they match correctly?

Cheers,

Tim (toledoh.com.au)

By Chris - April 30, 2014

Hi Tim,

The reason they're showing up is that the current record doesn't have a num yet; that is to say that @$RECORD['num'] is ''. You can add a test to the MySQL Where to avoid showing records when the current record doesn't have a num yet by adding this:

individual ='<?php echo mysql_escape(@$RECORD['num']) ?>
AND <?php echo (@$RECORD['num'] ? 'TRUE' : 'FALSE') ?>

Or perhaps this would be simpler:

individual ='<?php echo mysql_escape(@$RECORD['num']) ?>
AND individual > 0

On a side note, you may want to rename your field from individual to individualsNum (the name of the table, plus "Num"). The reason is that the Related Records' create link will attempt to populate a field with that name (and there's currently no way to customize that.) You can see it attempting to do that in the address bar when you click Create on a Related Records field; for example, for a Create button on my "test" table (with a self-referential Related Records relationship):

http://example.com/cmsAdmin/admin.php?menu=test&action=edit&testNum=7&returnUrl=%3Fnum%3D7%26menu%3Dtest%26action%3Dadd

I hope this helps! Please let me know if you have any questions.

All the best,
Chris

By Chris - May 9, 2014

Hi Tim,

No, if there's no problem, it's not important. Setting field names up like that is only useful for automatically filling in the field responsible for joining when creating a new record from a related records list. Just so you don't have to select the Individual from the dropdown, for example.

Hope this helps clear things up! :)

All the best,
Chris