How to get related records in delegate class?

A place for users and developers of the Xataface to discuss and receive support.

How to get related records in delegate class?

Postby 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.
kevinwen
 
Posts: 109
Joined: Mon Dec 28, 2009 3:44 pm

Re: How to get related records in delegate class?

Postby 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. :)
00Davo
 
Posts: 55
Joined: Sat Jan 02, 2010 9:02 pm

Re: How to get related records in delegate class?

Postby 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
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: How to get related records in delegate class?

Postby 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.
kevinwen
 
Posts: 109
Joined: Mon Dec 28, 2009 3:44 pm

Re: How to get related records in delegate class?

Postby shannah » Mon Feb 08, 2010 12:26 pm

The related record form just uses the same blocks as on the regular new/edit form.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: How to get related records in delegate class?

Postby 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?
kevinwen
 
Posts: 109
Joined: Mon Dec 28, 2009 3:44 pm

Re: How to get related records in delegate class?

Postby 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
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 9 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved