Showing posts with label relationships. Show all posts
Showing posts with label relationships. Show all posts

Tuesday, December 16, 2008

Getting related records

One thing you'll want to do is to grab related records in Xataface. Say for example, you have an abstract record that belongs to a conference. In the relationships.ini file of your abstract table, you would include something like this:


[Conference]
conference.ConferenceID="$AbstractConferenceID"


Where the conference is the name of the conference table, ConferenceID is the name of the index of that table, and $AbstractConferenceID is the foreign ID in your abstract record that corresponds to the the particular record in the conference table. Note the name of the relationship is "Conference."

In Xataface, if you have an abstract record you can quickly retrieve the related conference by simply doing this:


$conference = $record->getRelatedRecord('Conference')


This will retrieve the conference as a xataface_related_record object. It is important to realize that this is not the same thing as a xataface_record. If you want to convert this related_record object into a xataface_record object you can use the toRecord() function:

$conference = $record->getRelatedRecord('Conference')->toRecord();


This is a powerful technique that can save a lot of time.

Friday, May 9, 2008

Using the table relationship permissions function

Inside of each delegate class, we can use the function rel_nameOfRelationship__permissions(&$record) to specify the permissions on that relationship. The reason this works is because when we click on a tab to go to the relationship we are still in the original table.

For example, say we have a companies table that had a relationship to an offerings table. An offerings tab will be present. You can control the permissions on the tab (as in whether the user can add new offerings) by using that rel_nameOfRelationship__permissions(&$record) function.

In the event, that you want to actually remove that tab from the view, then you need to do this in the relationships.ini file of that table folder. Like this:

[offerings]
__sql__ = "SELECT * FROM offerings WHERE company_id ='$company_id'"
action:condition="isAdmin() or ($record->val('company_id') == getCompanyID()) or ( isBrokerDealer() and $record->val('company_id') == getDealerID())"
actions:addexisting=0
action:label="offerings"
section:sort="date_reported desc


  1. The __sql__ is just the SQL statement to retrieve the records

  2. action:condition is the part that determines whether the tab should appear or not.

  3. actions:addexisting makes it so that the add existing option doesn't appear



I found this strange bug (not sure if it is a bug). But if the try to enter action:condition = 0 just by itself it won't hide the tab. You have to enter action:condition = "false" in order for it to work...