Related Records

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

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 Toledoh - April 30, 2014

Hey Chris - that (2nd option) works perfectly!

Regarding your side note.  I don't quite understand - do you see a need to action it straight away?  Otherwise I will flag it for next time you guys are working on this project.  

Cheers,

Tim (toledoh.com.au)

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