Relating table to itself issue

80 views
Skip to first unread message

Edward Spiegel

unread,
Aug 10, 2017, 1:29:53 PM8/10/17
to xata...@googlegroups.com
Hi,

So, I have a situation where I have one to many relationship within a table.

My task table allows a task to have child tasks. (There is a field 'parent_id' that relates a child to the 'id' field of the task that spawned it).

To do this, I have created a view 'taskchildren' that is essentially just a clone of the 'tasks' table.

This works great for creating taskchildren and for seeing a list view of the task children.

Here is the gotcha. Clicking on a child task (from its parent's display view) doesn't work.

One way that I can address this would be to create a taskchildren.php and create a renderCell function that would manually build the link.

I am wondering, though, if there is a more elegant solution that wouldn't require this solution.

Thanks,
Edward

Steve Hannah

unread,
Aug 10, 2017, 1:33:19 PM8/10/17
to xata...@googlegroups.com
Can you be more specific about "doesn't work".  I might be able to suggest something to help.

--
You received this message because you are subscribed to the Google Groups "Xataface" group.
Visit this group at https://groups.google.com/group/xataface.
To view this discussion on the web visit https://groups.google.com/d/msgid/xataface/CAD-Qw9bTRT%3DbdVU5xa3wzNgWPavMHiN%3Dq51NeM0PZbgLhqvhrg%40mail.gmail.com.



--
Steve Hannah
Web Lite Solutions Corp.

Edward Spiegel

unread,
Aug 10, 2017, 2:01:19 PM8/10/17
to xata...@googlegroups.com
Hi Steve,

Below is a series of pictures that shows what I am talking about.


Here are the pictures
Inline image 1

A link from the 'task' list view (above) looks like this:
http://localhost:8888/bdbx/index.php?-table=tasks&-action=browse&-cursor=0&-skip=0&-limit=30&-mode=list&-recordid=tasks%3Fid%3D2

Inline image 2



Steve Hannah

unread,
Aug 10, 2017, 2:07:57 PM8/10/17
to xata...@googlegroups.com
Check both your PHP error log and Javascript error log.  There is likely something reported

Edward Spiegel

unread,
Aug 10, 2017, 2:25:37 PM8/10/17
to xata...@googlegroups.com
Nothing appears in the javascript error log/console

This is all that shows up in the php error log:

[10-Aug-2017 20:17:06 Europe/Berlin] PHP Deprecated:  mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /Users/edward/Web Dev/MAMPhtdocs/xataface downloads and docs/xataface dloaded 2017 06 19/xataface-master/xf/db/drivers/mysql.php on line 2
[10-Aug-2017 20:17:08 Europe/Berlin] PHP Deprecated:  mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /Users/edward/Web Dev/MAMPhtdocs/xataface downloads and docs/xataface dloaded 2017 06 19/xataface-master/xf/db/drivers/mysql.php on line 2
[10-Aug-2017 20:17:11 Europe/Berlin] PHP Deprecated:  mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /Users/edward/Web Dev/MAMPhtdocs/xataface downloads and docs/xataface dloaded 2017 06 19/xataface-master/xf/db/drivers/mysql.php on line 2
[10-Aug-2017 20:17:27 Europe/Berlin] PHP Deprecated:  mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /Users/edward/Web Dev/MAMPhtdocs/xataface downloads and docs/xataface dloaded 2017 06 19/xataface-master/xf/db/drivers/mysql.php on line 2

It looks to me like there is something funny about the hyperlinks in the list on the children tab but will admit that my head spins when I try to parse the link for correctness. On the other tabs, everything works fine (but those link to actual tables rather than a View).

FWIW, there is an entry for the taskchildren view in the conf.ini.

Thanks so much for a great tool,

Edward



Steve Hannah

unread,
Aug 10, 2017, 2:30:08 PM8/10/17
to xata...@googlegroups.com
Does your view have a primary key defined?

Edward Spiegel

unread,
Aug 10, 2017, 2:41:29 PM8/10/17
to xata...@googlegroups.com
Yes. And it works fine on its own. And creating child records from the parent records works fine. It is only when clicking on that link in the Children Tab list view that is a problem.

Here is another clue that I just noticed. When you are in the Display View of the parent record, the links from the list of children over on the left work fine. From there the link is:

http://localhost:8888/bdbx/index.php?-table=taskchildren&-action=browse&id=%3D17

which is different from the links displayed in the Children tab itself (see my previous message)

Inline image 1



Steve Hannah

unread,
Aug 10, 2017, 3:08:51 PM8/10/17
to xata...@googlegroups.com
I have just posted an update in github that should fix this issue.  Update to the latest and it should work now.

Edward Spiegel

unread,
Aug 10, 2017, 3:30:55 PM8/10/17
to xata...@googlegroups.com
Awesome. I'll grab it shortly.

Edward Spiegel

unread,
Aug 10, 2017, 4:21:40 PM8/10/17
to xata...@googlegroups.com
I just grabbed it, and I am still experiencing the problem.

Thanks again for looking into this,

Edward

Steve Hannah

unread,
Aug 10, 2017, 4:25:40 PM8/10/17
to xata...@googlegroups.com
Can you post the contents of your xataface/Dataface/templates/xataface/actions/view_related_record.html file ?  I want to verify that you are using the latest

Edward Spiegel

unread,
Aug 10, 2017, 4:29:47 PM8/10/17
to xata...@googlegroups.com
Here it is:

{if $ENV.resultSet->found() > 0}
    {use_macro file="Dataface_Record_Template.html"}
        {fill_slot name="record_content"}
        <div class="view-related-record-wrapper">


            <div class="subrecord-tabs">
                <ul>
                {assign var="rrecords" value=$related_record->toRecords()}
                {foreach from=$rrecords key=k item=subrecord}
                    {if $rrecords|@count <= 1 or $related_record->_relationship->hasUniqueFields($subrecord->_table->tablename)}
                        <li><a href="#tabs-{$k}">{$subrecord->getTitle()|escape}</a></li>
                    {/if}
                {/foreach}
                </ul>
                {foreach from=$related_record->toRecords(true) key=k item=subrecord}
                    {if $rrecords|@count <= 1 or $related_record->_relationship->hasUniqueFields($subrecord->_table->tablename)}
                        {record_view var=subrv record=$subrecord}
                        <div class="view-tab-content view-mode" id="tabs-{$k}" data-iframe-url="{$subrecord->getURL('-action=edit')|escape}" data-portal-id="{$related_record->getId()|escape}">
                            <div class="xf-button-bar-actions edit-related-record-actions-wrapper">
                                {actions_menu record=$subrecord category=edit_related_record_actions maxcount=7}
                            </div>
                            <div style="clear:both; height: 1px;"></div>
                            <div class="record-view-wrapper">
                                <div class="xf-button-bar-actions view-related-records-actions-wrapper">
                                    {actions_menu record=$subrecord category=view_related_record_actions maxcount=7}
                                </div>
                                <div style="clear:both; height: 1px;"></div>
                                <table class="view-record-columns" width="100%">
                                    <tr>
                                        <td id="dataface-sections-left-column" valign="top">
                                            <div class="dataface-sections-count-{$subrv->sections|@count} dataface-sections-left{if $subrv->showLogo} dataface-sections-left-with-logo{/if}" id="dataface-sections-left">
                                                {if $subrv->showLogo}
                                                    {if $subrv->logos|@count>0}
                                                        {foreach from=$subrv->logos item=logo}
                                                            <div class="dataface-view-logo">
                                                            {$related_record->htmlValue($logo.name)}
                                                            </div>
                                                        {/foreach}
                                                    {else}
                                                        <div class="dataface-view-logo">
                                                        <img src="{$ENV.DATAFACE_URL}/images/missing_logo.gif" alt="Missing Logo"/>
                                                        </div>
                                                    {/if}

                                                {/if}
                                                {block record=$subrecord table=$subrecord->_table->tablename name="before_record_actions"}
                                                {define_slot table=$subrecord->_table->tablename name="record_actions"}

                                                {/define_slot}
                                                {block record=$subrecord table=$subrecord->_table->tablename name="after_record_actions"}

                                                {foreach from=$subrv->sections item=section}
                                                    {if $section.class == 'left'}
                                                    {collapsible_sidebar heading=$section.label see_all=$section.url edit_url=$section.edit_url movable=1 id=$section.name prefix="leftsidebar" oncollapse="DatafaceSections.oncollapse(this)" onexpand="DatafaceSections.onexpand(this)" display=$section.display}
                                                        {define_slot table=$subrecord->_table->tablename name="`$section.name`_section_content"}
                                                        {if $section.content}
                                                            <div class="dataface-view-section">
                                                            {$section.content}
                                                            </div>
                                                        {elseif $section.fields}
                                                            <table class="record-view-table">
                                                            <tbody>
                                                            {foreach from=$section.fields item=field key=fieldname}
                                                                {if $field.visibility.browse != 'hidden' and $record->htmlValue($field.name)}
                                                                    <tr><th class="record-view-label">{$field.widget.label}</th><td class="record-view-value">{$record->htmlValue($field.name)}</td></tr>
                                                                {/if}
                                                            {/foreach}
                                                            </tbody>
                                                            </table>
                                                        {elseif $section.records}
                                                            {glance_list records=$section.records}
                                                        {/if}
                                                        {/define_slot}
                                                    {/collapsible_sidebar}
                                                    {/if}

                                                {/foreach}

                                            </div>
                                        </td>
                                        <td id="dataface-sections-main-column" valign="top">
                                            <div class="dataface-sections-main dataface-sections-count-{$subrv->sections|@count}" id="dataface-sections-main">
                                                {define_slot table=$subrecord->_table->tablename name="record_view_main_section"}
                                                    {if $ENV.prefs.collapse_all_sections_enabled}
                                                    <div class="section-tools">
                                                        <a href="javascript:DatafaceSections.collapseAll()"><img src="{$ENV.DATAFACE_URL}/images/treeExpanded.gif">Collapse All Sections</a> &nbsp; &nbsp;
                                                    <a href="javascript:DatafaceSections.expandAll()"><img src="{$ENV.DATAFACE_URL}/images/treeCollapsed.gif">Expand All Sections</a>
                                                    </div>
                                                    {/if}

                                                    {foreach from=$subrv->sections item=section}
                                                        {if $section.class == 'main'}
                                                        {collapsible_sidebar heading=$section.label edit_url=$section.edit_url movable=1 prefix="mainsidebar" id=$section.name onexpand="DatafaceSections.onexpand(this)" oncollapse="DatafaceSections.oncollapse(this)" display=$section.display}
                                                            {define_slot table=$subrecord->_table->tablename name="`$section.name`_section_content"}
                                                            {if $section.content}
                                                                <div class="dataface-view-section">
                                                                {$section.content}
                                                                </div>
                                                            {elseif $section.fields}
                                                                <table class="record-view-table">
                                                                <tbody>
                                                                {foreach from=$section.fields item=field key=fieldname}
                                                                    {if $field.visibility.browse != 'hidden'}
                                                                        {if $section.record}
                                                                            {assign var="field_value" value=$section.record->htmlValue($field.name)}
                                                                        {else}
                                                                            {assign var="field_value" value=$subrecord->htmlValue($field.name)}

                                                                        {/if}
                                                                        {if $field_value}
                                                                            <tr><th class="record-view-label">
                                                                                    {if $field.label_link}<a href="{$field.label_link|escape}" target="_blank" class="field-label-link no-link-icon">{/if}
                                                                                        {$field.widget.label}
                                                                                    {if $field.label_link}</a>{/if}
                                                                                </th>
                                                                                <td class="record-view-value">{$field_value}</td></tr>
                                                                        {/if}
                                                                    {/if}
                                                                {/foreach}
                                                                </tbody>
                                                                </table>
                                                            {elseif $section.records}
                                                                {glance_list records=$section.records}
                                                            {/if}
                                                            {/define_slot}
                                                        {/collapsible_sidebar}
                                                        {/if}

                                                    {/foreach}
                                                {/define_slot}
                                                <div style="clear:both"></div>

                                            </div>
                                            {literal}

                                             <script type="text/javascript">
                                            // <![CDATA[
                                                require(DATAFACE_URL+'/js/ajaxgold.js');

                                                var DatafaceSections = {

                                                    'setDisplay': function(el,disp){
                                                        var params = '--record_id=*&--name='+encodeURIComponent('tables.{/literal}{$record->_table->tablename}{literal}.sections.'+el.getAttribute('df:section_name')+'.display')+'&--value='+disp;
                                                        var query = window.location.search;
                                                        if ( query.indexOf('-action=') >= 0 ){
                                                            query = query.replace(/([?&])-action=[^&]+/g, '$1-action=ajax_set_preference');
                                                        } else {
                                                            query = '-action=ajax_set_preference';
                                                        }
                                                        query = query.replace(/^[?]/, '');
                                                        var url = DATAFACE_SITE_HREF;
                                                        //alert(url + " : " + params);
                                                        postDataReturnText(url, params + '&' + query, function(text){});

                                                    },

                                                    'oncollapse': function(el){
                                                        return this.setDisplay(el, 'collapsed');

                                                    },

                                                    'onexpand': function(el){
                                                        return this.setDisplay(el, 'expanded');
                                                    },
                                                    'collapseAll': function(){

                                                        var handles = getElementsByClassName(document,'*','expansion-handle');
                                                        for ( var i=0; i<handles.length; i++){
                                                            if ( !jQuery(handles[i].parentNode.nextSibling).hasClass('closed') ){
                                                                jQuery(handles[i].parentNode.nextSibling).slideToggle("slow", Xataface.blocks.collapsible_sidebar.toggleCallback);
                                                                //cd.collapseElement(handles[i]);
                                                            }
                                                        }
                                                    },
                                                    'expandAll': function(){
                                                        var handles = getElementsByClassName(document,'*','expansion-handle');
                                                        for ( var i=0; i<handles.length; i++){
                                                            if ( jQuery(handles[i].parentNode.nextSibling).hasClass('closed') ){
                                                                jQuery(handles[i].parentNode.nextSibling).slideToggle("slow", Xataface.blocks.collapsible_sidebar.toggleCallback);
                                                                //cd.collapseElement(handles[i]);
                                                            }
                                                        }
                                                    }


                                                };

                                                var updateSections = function(container){
                                                            //alert('here');

                                                            var params = window.location.search;//+'&'+Sortable.serialize("dataface-sections-left");
                                                            params = params.replace(/([?&])-action=[^&]+/g, '$1-action=ajax_sort_sections');


                                                            var movables = jQuery(container).find('.movable');
                                                            var movables_str = '';
                                                            for ( var i=0; i<movables.length; i++){
                                                                movables_str += ','+movables[i].getAttribute('df:section_name');
                                                            }
                                                            params += '&--'+encodeURIComponent(container.getAttribute('id'))+'='+encodeURIComponent(movables_str);
                                                            params = params.substring(1);
                                                            //alert(params);
                                                            postDataReturnText(DATAFACE_SITE_HREF, params, function(data){document.getElementById('terminal').innerHTML=data;});
                                                            //alert(Sortable.serialize("dataface-sections-left"));
                                                        }

                                                jQuery('#dataface-sections-left').sortable({'handle': '.movable-handle', 'update': function(){updateSections(jQuery('#dataface-sections-left').get(0));}});
                                                jQuery('#dataface-sections-main').sortable({'handle': '.movable-handle', 'update': function(){updateSections(jQuery('#dataface-sections-main').get(0));}});
                                                /*Sortable.create("dataface-sections-left",
                                                    {
                                                        dropOnEmpty:true,
                                                        constraint:false,
                                                        handle:'movable-handle',
                                                        tag:'div',
                                                        only:'movable',
                                                        onUpdate: updateSections
                                                    });
                                                Sortable.create("dataface-sections-main",
                                                {dropOnEmpty:true,constraint:false, handle:'movable-handle',tag:'div',only:'movable', onUpdate:updateSections});
                                            */
                                            // ]]>
                                             </script>
                                             {/literal}
                                            <div id="terminal"/>
                                        </td>
                                    </tr>
                                </table>
                                <div class="view-related-record-footer-actions">
                                    {actions_menu category="view_related_record_footer_actions" record=$subrecord}
                                </div>
                            </div><!-- record-view-wrapper-->

                        </div>
                     {/if}
                {/foreach}
            </div>
        </div><!-- view-related-record-wrapper-->
        {/fill_slot}
    {/use_macro}
{else}
    {use_macro file="Dataface_Main_Template.html"}
        {fill_slot name="record_content"}
            {translate id="scripts.GLOBAL.NO_RECORDS_MATCHED_REQUEST"}No records matched your request.{/translate}
        {/fill_slot}
    {/use_macro}

{/if}


Steve Hannah

unread,
Aug 10, 2017, 4:31:05 PM8/10/17
to xata...@googlegroups.com
That should be working.  Try clearing out your templates_c directory.


Edward Spiegel

unread,
Aug 10, 2017, 4:31:59 PM8/10/17
to xata...@googlegroups.com
Ooops! Just noticed that I goofed in setting up the symbolic link to the latest version.

Many apologies.
Edward

Edward Spiegel

unread,
Aug 10, 2017, 4:33:47 PM8/10/17
to xata...@googlegroups.com
I really appreciate your having solved this and am really really sorry for the false alarm and carelessness on my part.

Best,

Edward
Reply all
Reply to author
Forward
0 new messages