Help with Add Existing Related Record functionality

532 views
Skip to first unread message

Jennifer Weston

unread,
Apr 9, 2015, 1:55:24 PM4/9/15
to xata...@googlegroups.com
Hi there,

Our small IT team has been successfully using the Xataface interface for over a year now. It is a great framework and I have successfully converted others in our organization into using it -- thank you for creating it. 

Right now, however, I am stuck and have been spinning my wheels on this problem for several days, so I'm hoping someone can point me in the right direction.

Desired End Result: 
Among other things, our team uses Xataface to document server configurations for servers we manage. In addition to documenting a lot of other information on each server, I need to show for each server which hard drives are currently in it and which compatible hard drives are available as spares. I also want it to be easy for the sysadmin to document that a compatible spare was added to a server so he can just go into the server's individual record in the server table and check a box next to the compatible spare drive to add it as a related record. For example, server-1 presently has:
2.5 SAS 146 GB Dell ST9146803SS 10
2.5 SAS 146 GB Dell ST9146803SS 10

The sysadmin needs to add a third drive to this device. I want him to be able to see only the 2.5 SAS drives.

Scope of Problem:
Two tables, one named servers and one named drives. They are related in a 1:m relationship since one server will contain many unique drives.
Table servers lists various attributes of servers we manage.
Here are the relevant columns from my servers table:
CREATE TABLE `servers` (
  `name` varchar(45) NOT NULL,
  `hddcurrentcount` enum('0','1','2','3','4','5','6','7','8','9','10','10+') DEFAULT '1',
  `hdddimensions` varchar(10) DEFAULT NULL,
  `hddtype` enum('SATA','SAS','IDE') DEFAULT NULL,
  PRIMARY KEY (`name`),
  UNIQUE KEY `name_UNIQUE` (`name`)

Table drives lists of all the hard drives in the servers and any spare hard drives we have on hand.
Here are the relevant columns from my drives table:
CREATE TABLE `drives` (
  `itemid` int(11) NOT NULL AUTO_INCREMENT,
  `drivedimensions` varchar(45) DEFAULT NULL,
  `drivetype` enum('SATA','SAS','IDE','EIDE') NOT NULL,
  `drivesize` int(11) DEFAULT NULL,
  `drivemanufacturer` varchar(45) DEFAULT NULL,
  `drivemodel` varchar(45) DEFAULT NULL,
  `drivespeed` varchar(45) DEFAULT NULL,
  `inserver` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`itemid`),
  UNIQUE KEY `drivesizeid_UNIQUE` (`itemid`)
)

The relationships.ini file for servers contains:
;Sparedrives selects only the compatible drives
[sparedrives]
action:label="Spare Drives That Potentially Fit This Model"
section:visible=0
action:visible=0
actions:addexisting=1
visibility:find=0
visibility:itemid = hidden
visibility:inserver = hidden
visibility:drivedimensions = visible
visibility:drivetype = visible
__sql__ = "SELECT * FROM drives WHERE drives.drivedimensions = '$hdddimensions' AND drives.drivetype = '$hddtype' AND drives.inserver IS NULL ORDER BY drives.drivesize"

;drives relationship selects drives already in the server
[drives]
action:label="Current Drives in this Machine"
section:visible=0
action:visible=0
visibility:find=0
actions:addexisting=1
__sql__ = "SELECT * FROM drives WHERE drives.inserver = '$name'"

Ideal Solution, buildRelatedSection+add existing related record action
I regularly use the buildRelatedSection function in my table delegate file (e.g. tablename.php) for displaying related records since having related records displayed in the same tab as the parent record is much easier for my teammates to use. This works and I like it. Ideally I'd like to use the "Add Existing Related Record" button that comes with this. However, this has not worked properly. When I rely on the built-in add_existing_related_record_g2 action from the g2 module directory, I get an error which includes: 

Fatal error: Uncaught exception 'Exception' with message '[pear_error: message="Error. No relationship was specified when trying to add existing related record." code=200 mode=return level=notice prefix="" info=""]'

So then I added a custom action to my actions.ini file for servers table which includes the bolded line:
[add_existing_related_phs > add_existing_related_record_g2]
label="Add Existing Record"
description="Add an existing {$relationship->getSingularLabel()} it to the {$record->getTitle()}"
label_condition="$relationship"
description_condition="$relationship"
condition="$relationship and $relationship->supportsAddExisting()"
permission="add existing related record"
category=related_list_actions
url="{$this->url('-action=existing_related_record&-relationship=sparedrives')}"
order=-999

Now I get an error that states: 
"Errors"
"There were no records that can be added to this relationship" 
"Permission Denied".
However, I don't have any permissions restricted for either table or in the application permissions file for this user account, which has out of the box ADMIN role. I have checked the permissions file for my application again and again and I'm completely baffled about this error. If i change the permission in the servers\actions.ini file to "edit", for example, I still receive the permissions error.

I have cleared the cache each time to ensure nothing is being cached.

Another solution - Checkboxes+titleColumn
After trying to get the above solution to work for a while with no luck, I tried the problem from a different angle. I decided it would work about as well to allow the administrator to go into the edit form for each server to check a box next to a compatible hard drive that he wants to add to a server. To do this, in my fields.ini file I added this field:
[addspare]
group=hdd
widget:label="Add a Spare Hard Drive"
widget:type=checkbox
transient=1
order=995
relationship=drives
widget:columns = 2

And to correspond with it, in the drives.php file in the drives table folder, I added the following function:
function titleColumn(){
return "CONCAT_WS('',drivemanufacturer,' ',drivetype,' ',drivedimensions,' in ',drivesize,'GB, ',drivespeed)";
}
This works fine, but it displays all of the hard drives, not just the ones that are compatible. I cannot get any SQL syntax to work to do a WHERE clause and only select, for example SATA drives that are 3.5. If I change the relationship=sparedrives, all that is displayed is the PK of the drives table, which is an ID and not useful to the sysadmin. 


I am definitely open to other solutions to this problem.
I sincerely appreciate any help anyone can provide. I've been able to work through most of my other issues with Xataface previously but with this problem I'm at a loss.

Thank you very much.

- Jenni

Steve Hannah

unread,
Apr 9, 2015, 2:11:18 PM4/9/15
to xata...@googlegroups.com
When you receive the "No relationship was specified when trying to add existing related record" can you post the URL that appears in your location bar?  (I'm only interested in what's after the ?)

Steve

--
You received this message because you are subscribed to the Google Groups "Xataface" group.
Visit this group at http://groups.google.com/group/xataface.
To view this discussion on the web visit https://groups.google.com/d/msgid/xataface/617bfba2-1ad9-4696-a034-c620051960f5%40googlegroups.com.



--
Steve Hannah
Web Lite Solutions Corp.

Jennifer Weston

unread,
Apr 9, 2015, 2:35:39 PM4/9/15
to xata...@googlegroups.com

Jennifer Weston

unread,
Apr 9, 2015, 2:37:20 PM4/9/15
to xata...@googlegroups.com
Also I should state that this is an Intranet-only web server. It's not accessible from the Internet.

Steve Hannah

unread,
Apr 9, 2015, 2:44:32 PM4/9/15
to xata...@googlegroups.com
On this line

Please add the following:
print_r($query);exit;

Then can you post the result here?  For some reason it isn't picking up the -relationship arg.

Steve

Jennifer Weston

unread,
Apr 9, 2015, 2:57:46 PM4/9/15
to xata...@googlegroups.com
Thank you, here is the result.

Array ( [-table] => servers [-limit] => 1000 [-action] => existing_related_record [-cursor] => 15 [-skip] => 0 [-mode] => browse [-recordid] => servers?name=SRV-VMH-00 [-relationship] => sparedrives [--original_action] => existing_related_record )

Steve Hannah

unread,
Apr 9, 2015, 3:06:00 PM4/9/15
to xata...@googlegroups.com
That doesn't add up.  It shows that the '-relationship' directive is indeed specified, but it is throwing an error that should only occur when that isn't specified.  Can you confirm that it is throwing the error there?  That doesn't make any sense.

Jennifer Weston

unread,
Apr 9, 2015, 3:33:10 PM4/9/15
to xata...@googlegroups.com
Yeah. So if I comment out line 12 in xataface\existing_related_record.php like so:
//print_r($query);exit;

Then I pressed the refresh button on the page with the URL of:
I get the error. I attached a screenshot.

As I mentioned, I don't have a permissions.ini in the servers table folder or in the drives table folder. I do have permissions.ini set in the main application folder (rc_nsa).

Here's my permissions.ini folder within my xataface application folder, just in case that helps. I am logged on with an account that has the ADMIN role. 

htdocs\rc_nsa\permissions.ini contents:
[EDIT extends EDIT]
import=0

[LIMITED]
import=0
view=1
link=1
show all=1
list=1
calendar=1
view xml=1
show all=1
find=1
navigate=1
ajax_load=1
find_list=1
find_multi_table=1
rss=1
export_csv=1
export_xml=1
export_json=1
view related records=1

Here is the contents of my ApplicationDelegate.php file. Let me know if having any other information from my site might help. I had previously wondered if maybe I accidentally edited a xataface base file or something. Earlier today I recreated my site from the latest github trunk of xataface; I backed up the old xataface folder and re-imported the latest version of xataface from github and then re-added missing modules but that didn't have any effect. I can't think of any other location where this kind of configuration would be changed, but perhaps you might?

/**
 * A delegate class for the entire application to handle custom handling of 
 * some functions such as permissions and preferences.
 */
class conf_ApplicationDelegate {


/** Enables custom javascript file
*/
function block__custom_javascripts(){
    echo '<script src="http://srv-web-01/rc_nsa/javascripts.js" type="text/javascript" language="javascript"></script>';
}

    /**
     * Returns permissions array.  This method is called every time an action is 
     * performed to make sure that the user has permission to perform the action.
     * @param record A Dataface_Record object (may be null) against which we check
     *               permissions.
     * @see Dataface_PermissionsTool
     * @see Dataface_AuthenticationTool
     */
public function beforeHandleRequest(){
    Dataface_Application::getInstance()
        ->addHeadContent(
            sprintf('<link rel="stylesheet" type="text/css" href="%s"/>',
                htmlspecialchars(DATAFACE_SITE_URL.'/style.css')
            )
        );
}

     function getPermissions(&$record){
         $auth =& Dataface_AuthenticationTool::getInstance();
         $user =& $auth->getLoggedInUser();
         if ( !isset($user) ) return Dataface_PermissionsTool::NO_ACCESS();
             // if the user is null then nobody is logged in... no access.
             // This will force a login prompt.
         $role = $user->val('Role');
         return Dataface_PermissionsTool::getRolePermissions($role);
             // Returns all of the permissions for the user's current role.
      }
   
function isAdmin(){
    $auth =& Dataface_AuthenticationTool::getInstance();
    $user =& $auth->getLoggedInUser();
    if ( $user and $user->val('Role') == 'ADMIN' ) return 'ADMIN';
elseif ( $user and $user->val('Role') == 'EDIT' ) return 'EDIT';
    elseif ( $user and $user->val('Role') == 'READ ONLY' ) return 'READ ONLY';
elseif ( $user and $user->val('Role') == 'LIMITED' ) return 'LIMITED';
elseif ( $user and $user->val('Role') == ('NO ACCESS' or $null) ) return 'NO ACCESS';
}

 
function getNavItem($key, $label){
$getroles =& conf_ApplicationDelegate::isAdmin();
    if ($getroles == 'EDIT'){
        switch ($key){
case '':
                // non-admin users can see these
throw new Exception("Use default rendering");
        }
        // Non-admin users can't see any other table.
        return null;
 
    } elseif ($getroles == 'ADMIN') {
        switch ($key){
case '':
                throw new Exception("Use default rendering");
        }
    }
elseif ($getroles == 'NO ACCESS'){
        switch ($key){
            case '':
                // non-admin users can see these
                throw new Exception("Use default rendering");
error_xataface.PNG

Steve Hannah

unread,
Apr 9, 2015, 3:39:14 PM4/9/15
to xata...@googlegroups.com
You shouldn't have to comment that out.  Something is seriously wrong.  Could be a problem with your PHP install... you should really poke around that "if" statement to see why it is returning true, when the rule clearly should return false.

I don't think it's worth pushing on unless that is resolved because there could be something more fundamentally wrong.

Steve

Jennifer Weston

unread,
Apr 9, 2015, 3:48:52 PM4/9/15
to xata...@googlegroups.com
I'm sorry but I don't think I follow. I commented out the line you told me to add to the existing_related_record.php file (line 12):

Inline image 2

If it's not commented out, clicking on the Add Existing Record shows this:

Inline image 1
You said: "you should really poke around that "if" statement to see why it is returning true, when the rule clearly should return false."

Which if statement? I'm afraid my limited knowledge is getting in the way of me understanding your advice. I appreciate any clarification you can provide.

Thank you.

Jennifer Weston

unread,
Apr 9, 2015, 3:52:19 PM4/9/15
to xata...@googlegroups.com

I'm sorry but I don't think I follow. I commented out the line you told me to add to the existing_related_record.php file (line 12) so that I could confirm it was still throwing the error on the add existing related record page for that record. Here's the commenting out:

Inline image 2

If it's not commented out, clicking on the Add Existing Record shows this below image. If it is not supposed to show this, what should I see?

Inline image 1
You said: "you should really poke around that "if" statement to see why it is returning true, when the rule clearly should return false."

Which if statement? I'm afraid my limited knowledge is getting in the way of me understanding your advice. I appreciate any clarification you can provide and agree that pressing forward at this point while ignoring this error is not an option.

Thank you.

Steve Hannah

unread,
Apr 9, 2015, 3:56:15 PM4/9/15
to xata...@googlegroups.com
I asked for the URL of the page that displayed this error:
Error. No relationship was specified when trying to add existing related record.

You added some debugging code to show the contents of $query just before this error is thrown.

Now you say that removing the debugging code results in a different error message?  (I.e. adding and removing the debugging code fixed the issue?).   Something is missing here.

Steve

Jennifer Weston

unread,
Apr 9, 2015, 4:18:36 PM4/9/15
to xataface
Oh no, my apologies. Removing the debugging code resulted in the same permission denied error that I included in my first post:

"Errors"
"There were no records that can be added to this relationship" 
"Permission Denied".

Steve Hannah

unread,
Apr 9, 2015, 4:20:28 PM4/9/15
to xata...@googlegroups.com
I asked to see the URL page that gives you this error:
Fatal error: Uncaught exception 'Exception' with message '[pear_error: message="Error. No relationship was specified when trying to add existing related record." code=200 mode=return level=notice prefix="" info=""]'

Steve Hannah

unread,
Apr 9, 2015, 4:21:04 PM4/9/15
to xata...@googlegroups.com
The other errors occurred after you had already done some custom workarounds so that is harder for me to troubleshoot.

Jennifer Weston

unread,
Apr 10, 2015, 8:52:03 AM4/10/15
to xata...@googlegroups.com
I am terribly sorry. I misunderstood before, and I appreciate your patience to help me sort this out. 

Here's the debugging information that shows up when I clicked the button that corresponds with the error (Fatal error: Uncaught exception 'Exception' with message '[pear_error: message="Error. No relationship was specified when trying to add existing related record." code=200 mode=return level=notice prefix="" info=""]') you requested:

Array ( [-table] => servers [-limit] => 1000 [-action] => existing_related_record [-cursor] => 15 [-skip] => 0 [-mode] => browse [-recordid] => servers?name=SRV-VMH-00 [--original_action] => existing_related_record )


Perhaps there is something missing somewhere for telling the action how to find the relationship? The add existing related record button does not work for any of the tables in my application... the drives and servers tables are just two of 18 tables in the database. However, until I created the servers and drives tables, I had not needed to implement this functionality on the other tables, but if I go and attempt to reveal this in other tables it does not work there either... so this shows it is an application-wide problem and not specific to this table. Also, this is the only Xataface application I have installed on this server.

Steve Hannah

unread,
Apr 10, 2015, 3:11:47 PM4/10/15
to xata...@googlegroups.com
Yes.  The -relationship directive is not being passed along.

What version of Xataface are you using?  (Is it from the GitHub master, or a release?)
Are you using the G2 theme?
What is the URL of the page where you click the "Add Existing Related Record" button?
Can you post your xataface/modules/g2/actions.ini file so I can take a look?

(Do you have two copies of the g2 theme installed by any chance?  -- one in your modules/g2 directory and the other in xataface/modules/g2?)

Steve

Jennifer Weston

unread,
Apr 10, 2015, 3:53:04 PM4/10/15
to xata...@googlegroups.com
The version.txt file in the xampp\htdocs\xataface directory says 2.1.2.4208.

Version of Xataface
Yesterday as part of my troubleshooting measures and actually before posting the initial post, I archived the old version of Xataface by moving the old xataface directory (2.0.3.4798) out to a backup location and then re-downloaded the latest version (zip file) that you have here: https://github.com/shannah/xataface. From the archive folder to the xampp\htdocs\xataface directory I copied back the excel, ajax_upload, ckeditor, tagger, depselect, email, durationselector, and Auth modules. The g2 and XataJax modules in the xataface\modules folder are from the zip file I downloaded yesterday and I left them alone. I also disabled all the modules in the conf.ini file to see if that had any effect on producing a different error when clicking the Add Existing button hoping if a module was causing the problem, I could isolate it, but disabling all of the modules did not provide any different result with regard to the Add Existing functionality.

G2 Theme
Yes, I am using the G2 theme. In the xampp\htdocs\xataface\modules\g2 folder the version.txt file reads 0.1.1 2.

The URL of the page for Add Existing Related Record (Add Existing Related Record is the button for the custom action I made in the actions.ini file)
This provides the permission denied error.
URL of the page for Add Existing Button is the one that is there by default regardless of what I have in the actions.ini file.
This provides the "no relationship specified" error.

g2 Versions
The only g2 version I have is in my xampp\htdocs\xataface\modules folder. My application modules folder (xampp\htdocs\rc_nsa\modules) is empty.

g2\actions.ini
Here is the contents of the actions.ini file from \xampp\htdocs\xataface\modules\g2\actions.ini file:

[logout > logout]
url="{$site_href}?-action=logout"
condition="df_is_logged_in()"
label="Log Out"
description="Log out of the system"
category=personal_tools
order=100
[login > login]
url="{$site_href}?-action=login"
condition="!df_is_logged_in() and @$this->_conf['_auth']"
label="Log In"
description="Log into the system"
category=top_right_menu_bar
[show_all > show_all]
category=""
[copy_replace_ui > copy_replace_ui]
category=""
[update_set > update_set]
category=""

[delete > delete]
category=""
[delete_found > delete_found]
category=""
[export_list]
category=result_list_actions
label="Export"
description="Export this result set as ..."
url="#"
class="export-list"
subcategory=list_export_actions
[delete_results > delete_selected]
category=result_list_actions
label="Delete"
description="Delete selected records"
class="delete-results right-btn selected-action"
order="-98"
url="{$this->url('-action=delete_selected')}"
[copy_results > copy_replace_ui]
category=result_list_actions
label="Copy"
description="Copy selected records"
class="copy-results left-btn selected-action"
order="-100"
[update_results > update_set]
category=result_list_actions
label="Update"
description="Update selected records"
class="update-results middle-btn selected-action"
order="-99"
[export_xml > export_xml]
category=list_export_actions
[export_csv > export_csv]
category=list_export_actions
[rss > rss]
category=list_export_actions

[export_record]
category=record_actions
label="Export"
description="Export this record as ..."
url="#"
class="export-record"
subcategory=record_export_actions

[view_xml > view_xml]
category=record_export_actions
[record_rss > record_rss]
category=record_export_actions
[edit_record > edit]
category=record_actions
order=-100
description="Edit this record"
condition="$query['-action'] != 'edit'"
[cancel_edit_record > view]
label="Cancel"
description="Cancel Edit"
condition="$query['-action'] == 'edit'"
category=record_actions
order=-100

[delete_record > delete]
category=record_actions
order=-99

[record_back > list]
category=record_actions
order=-1500
label=""
class="record-back"
description="Return to list view"

[view > view]
label="Details"
[edit > edit]
category=""
[add_new_related_record_g2]
label="New {$relationship->getSingularLabel()}"
description="Create a new {$relationship->getSingularLabel()} and add it to the {$record->getTitle()}"
label_condition="$relationship"
description_condition="$relationship"
condition="$relationship and $relationship->supportsAddNew()"
permission="add new related record"
category=related_list_actions
url="{$this->url('-action=new_related_record')}"
order=-1000
[add_existing_related_record_g2]
label="Add Existing"
description="Add an existing {$relationship->getSingularLabel()} it to the {$record->getTitle()}"
label_condition="$relationship"
description_condition="$relationship"
condition="$relationship and $relationship->supportsAddExisting()"
permission="add existing related record"
category=related_list_actions
url="{$this->url('-action=existing_related_record')}"
order=-999

[export_related]
subcategory=related_export_actions
category=related_list_actions
label=Export
[related_rss > related_rss]
category=related_export_actions
[related_xml > related_xml]
category=related_export_actions
[export_csv_related > export_csv_related]
category=related_export_actions
[search_related]
category=related_list_actions
url="#"
order=-50
label="Filter"
description="Filter {$relationship->getLabel()} using a keyword search."
description_condition="$relationship"
class="search-relationship-action"
condition="$relationship"
onclick="Dataface.RelatedList.showSearch('{$relationship->getName()}', document.getElementById('related_find_wrapper')); return false;"
onclick_condition="$relationship"
[copy_related]
category=related_list_actions
url="{$this->url('-action=copy_replace')}&-from={$query['-action']}&--copy=1"
order="-100"
label="Copy"
description="Copy selected {$relationship->getLabel()}"
description_condition="$relationship"
class="xf-copy-related-records left-btn related-selected-action"

[update_related]
category=related_list_actions
url="{$this->url('-action=copy_replace&-from='.$query['-action'])}"
order="-99"
label="Update"
description="Update values in selected {$relationship->getLabel()}"
description_condition="$relationship"
class="xf-update-related-records middle-btn related-selected-action"
permission = update related records
[remove_related]
category=related_list_actions
url="{$this->url('-action=remove_related_record')}&-from={$query['-action']}"
order="-98"
label="Remove"
description="Remove selected rows from {$relationship->getLabel()}"
description_condition="$relationship"
class="xf-remove-related-records right-btn related-selected-action"
permission = remove related record
[new > new]
label="New {$tableObj->getSingularLabel()}"
label_condition="$tableObj"
description="Insert a new {$tableObj->getSingularLabel()} into {$tableObj->getLabel()}"
description_condition="$tableObj"
[import > import]
label="Import {$tableObj->getLabel()}"
label_condition="$tableObj"
[cancel_add_new_related_record]
label="Cancel"
description="Cancel this form.  Return to {$relationship->getLabel()}"
description_condition="$relationship"
url="{$this->url('-action=related_records_list')}"
category=add_new_related_record_actions
order="-1000"
[save_add_new_related_record]
label="Save"
description="Save this form."
url="#"
category=add_new_related_record_actions
order=-999
class="xf-save-new-related-record"
[cancel_new_record_form]
label="Cancel"
description="Cancel this form.  Return to list view."
url="{$this->url('-action=list')}"
category=new_record_form_actions
order=-1000
[save_new_record_form]
label="Save"
description="Save this form"
url="#"
category="new_record_form_actions"
order=-999
class="xf-save-new-record"
[cancel_edit_record_form > cancel_new_record_form]
url="{$this->url('-action=view')}"
category=edit_record_form_actions
description="Cancel editing.  Return to view mode."
[save_edit_record_form > save_new_record_form]
category=edit_record_form_actions
[personal_menu]
category=top_right_menu_bar
label="{$this->getAuthenticationTool()->getLoggedInUserName()}"
label_condition="$this->getAuthenticationTool()"
condition="$this->getAuthenticationTool() and $this->getAuthenticationTool()->isLoggedIn()"
subcategory=personal_tools
order=-100
[control_panel]
category=top_right_menu_bar
label="Control Panel"
permission="manage"
order=-101
subcategory=management_actions
;[languages]
; category=top_right_menu_bar
; label="Language"
; permission="view"
[view_menu]
category=result_list_actions
label="View"
subcategory=table_tabs
order=-2000
class="list-view-menu"
[browse > browse]
category=""
[find > find]
category=""

[configure_advanced_search_form]
class="configure-advanced-find-form-action"
category=advanced_search_actions
url="{$this->url('-action=show_hide_columns')}&--relationships=*&--visibility-types=find"
label="Configure Search Form..."
permission="show hide columns"


...

Steve Hannah

unread,
Apr 10, 2015, 4:23:54 PM4/10/15
to xata...@googlegroups.com
Thanks.  What is the URL of the page on which the "Add Existing Related Record" button appears?  I.e. before you click "Add Existing Related Record", what is the URL?

Steve

Jennifer Weston

unread,
Apr 10, 2015, 4:38:02 PM4/10/15
to xata...@googlegroups.com

Steve Hannah

unread,
Apr 10, 2015, 4:40:35 PM4/10/15
to xata...@googlegroups.com
Hmm.  That button shouldn't even show up there.  It should only show up on the related list page for a particular relationship.  How do your users know the context of this button?  E.g. They are on the "browse" page for a server record, and they see a button that says "Add Existing Related Record", how do they know what they're adding?

Steve

--
You received this message because you are subscribed to the Google Groups "Xataface" group.
Visit this group at http://groups.google.com/group/xataface.

Jennifer Weston

unread,
Apr 10, 2015, 5:14:54 PM4/10/15
to xata...@googlegroups.com
So, the button "Add Existing" related record shows up there because I followed unofficial documentation you had created to allow related records to show up in the same records tab as the record itself, as a sub-table, using the following two pieces in the servers.php table delegate. See the code below. The reason it needs to show up in the same tab is that some of my teammates won't understand the tabbed structure, and so having everything, including related records, on the record page is essential for them to comply with procedure. I attached a picture of what I have currently. Additional fields from the servers table are not shown.

Adding related records sub-table in the application delegate to allow related records to show up in the same tab as the primary record:

function buildRelatedSection(Dataface_Record $record, $relationship){
      import('Dataface/RelatedList.php');
      $relatedList = new Dataface_RelatedList($record, $relationship);
      $relatedList->noLinks = false;
      $relatedList->hideActions = false;
      $content = $relatedList->toHtml();      
      $rel = $record->table()->getRelationship($relationship);
       
       return array(
          'class'=>'main',
          'content'=>$content,
          'label'=>$rel->getLabel(),
          'order'=>50
       );
    }

function section__sparedrives($record){
       return $this->buildRelatedSection($record, 'sparedrives');
    }


...
xataface_servers_drives.png

Alan Dobkin

unread,
Apr 10, 2015, 5:15:01 PM4/10/15
to xata...@googlegroups.com
If I'm understanding this correctly, Jennifer is trying to streamline her app by skipping the step of clicking on the related page. She wants users to be able to add spare drives (related items) to the server directly from the server browse page. The button really should be labeled "Add Spare Drive" in this case, rather than the generic "Add Existing Record" text. The button is appearing because she added the following custom action:

[add_existing_related_phs > add_existing_related_record_g2]
label="Add Existing Record"
description="Add an existing {$relationship->getSingularLabel()} it to the {$record->getTitle()}"
label_condition="$relationship"
description_condition="$relationship"
condition="$relationship and $relationship->supportsAddExisting()"
permission="add existing related record"
category=related_list_actions
url="{$this->url('-action=existing_related_record&-relationship=sparedrives')}"
order=-999

The only change I see here from the default add_existing_related_record_g2 action is this additional parameter at the end of the url: &-relationship=sparedrives

So, I think the basic question is, how can items be added from a specified relationship directly from the view tab? I can see this being useful in other applications as well.

On 4/10/15 4:40 PM, Steve Hannah wrote:

Alan Dobkin

unread,
Apr 10, 2015, 5:26:02 PM4/10/15
to xata...@googlegroups.com
FYI, for reference, I found the original post where the buildRelatedSection function was described:

http://xataface.com/forum/viewtopic.php?f=4&t=4231&start=15

It looks like that poster had a similar problem with the add related record button.


On 4/10/15 5:14 PM, Jennifer Weston wrote:

Jennifer Weston

unread,
Apr 10, 2015, 5:37:56 PM4/10/15
to xata...@googlegroups.com
Thanks Alan, yes, that is what I want to do. As I mentioned in the first post, there are three potential ways to do this:

1. The out of the box Add Existing functionality which does not seem to work.
2. A custom action in actions.ini that links directly to the relationship, which gives the permissions error.
3. In the edit form for the server record, a set of checkboxes for each compatible drive with all of the fields concatenated, which I cannot get to work properly.

So here's some more interesting information I acquired while trying to drill down the problem with option number 2...
It appears to be the SQL statement in the relationships.ini which is generating the permission denied error.

This generates the error: __sql__ = "SELECT * FROM drives WHERE drives.drivedimensions = '$hdddimensions' AND drives.drivetype = '$hddtype' AND drives.inserver IS NULL"

This generates the error: __sql__ = "SELECT * FROM drives WHERE drives.drivedimensions = '$hdddimensions' AND drives.drivetype = '$hddtype'"

This generates the error: __sql__ = "SELECT * FROM drives WHERE drives.drivedimensions = '$hdddimensions' AND drives.drivetype = '$hddtype AND drives.inserver = '$name'"

This works: __sql__ = "SELECT * FROM drives WHERE drives.inserver = '$name'"
This is the first time I've seen the add existing related records screen which is a select list.

So, it seems that something about it can't handle the AND arguments in the SQL statement..... even though it displays the related records just fine.

Steve Hannah

unread,
Apr 10, 2015, 5:38:38 PM4/10/15
to xata...@googlegroups.com
OK.  Thanks guys.  I understand the problem better now.

So after your workaround, it is failing on this line:

Which means that it is checking getAddableValues() for the relationship, and didn't find any.  You can see the implementation of getAddableValues() here:


So there are a few places to look:

1. If you've implemented the relationshipname__getAddableValues() method in the delegate class and aren't returning any records.
2. If you've specified a custom vocabulary:existing directive to the relationship that isn't finding anything.
3. The getTitles() query is coming up empty.  

Do some debugging in that method to see which case it is hitting.

Steve

--
You received this message because you are subscribed to the Google Groups "Xataface" group.
Visit this group at http://groups.google.com/group/xataface.

Jennifer Weston

unread,
Apr 10, 2015, 8:19:15 PM4/10/15
to xata...@googlegroups.com
Thanks Steve,

That makes sense, however I have not implemented any of those three things in my application anywhere. I looked at the getAddableValues() link you sent but I'm afraid it's a little over my experience level to understand what each part means. Can you give me a further hint on how to debug?

Also I think a clue may be in my previous post about the SQL query, which in fact does not link the PK with its FK. Really at the base of it I just need a method to display the concatenated fields of the child table through the parent record with filters on three fields. I thought about creating a SQL view to accomplish that but since the filter has to be defined by a variable I'm not sure it would be useful. I see filters are no longer possible within the relationships.ini file but if there is some other way to go about accomplishing this, I'm open to creative ideas and rolling up my sleeves.

Thank you for your continued help and attention. The level of support you provide for this interface is superior to any other individual I've worked with.

Sincerely,
Jenni
Reply all
Reply to author
Forward
0 new messages