How to get related records in delegate class?
Archived from the Xataface Users forum.
kevinwen — Mon Feb 01, 2010 11:35 am
I defined a relationship with songs table in artists table’s relationships.ini, so there is a songs tab appears next to edit tab. Now I want to get all related songs for a specific artist in one of after_action_edit trigger. Can I use df_query() to get those related records? How? Is there any other way to do the same thing besides df_query()? thanks.
00Davo — Tue Feb 02, 2010 7:40 pm
Sure. Assuming you’ve got the record object as $record…
- Code: Select all
$songs = $record->getRelatedRecordObjects("Songs"); // array of objects //alternately $songs = $record->getRelatedRecords("Songs"); //array of arrays
Should work just fine.
shannah — Thu Feb 04, 2010 12:12 pm
One caveat is that getRelatedRecords and getRelatedRecordObjects return only the first 30 rows by default (for your safety). You can control how many rows are returned by adding some additional parameters:
Check out more about these at http://dataface.weblite.ca/getRelatedRecords
or
http://dataface.weblite.ca/getRelatedRecordObjects
Another useful function is
numRelatedRecords
http://dataface.weblite.ca/numRelatedRecords
kevinwen — Sun Feb 07, 2010 8:42 pm
Thank you so much. There is another question further: What delegate method can we use for the related records, like those __pullVale(), block__after_new_record_form() for the current table’s records? I need to do something in the new/edit related record form? Thanks.
shannah — Mon Feb 08, 2010 12:26 pm
The related record form just uses the same blocks as on the regular new/edit form.
kevinwen — Mon Feb 08, 2010 5:46 pm
If I want to output some javascript using block__after_new_record_form(), which delegate class should I put this function into?
shannah — Mon Feb 08, 2010 5:58 pm
The best way to see what blocks are available is to set
- Code: Select all
debug=1
at the beginning of the conf.ini file. Then load the form you want to modify. It will print out all of the blocks and slots on the page.
-Steve