Relationships & Related data views

324 views
Skip to first unread message

Zack Hayato

unread,
Dec 25, 2014, 7:12:47 PM12/25/14
to xata...@googlegroups.com
Hi, everyone..

I have created relationships for a table using the cross-reference table method..

Table_A
store_id

Table_B
item_id

Table_C
store_id
item_id

-------------------------------------

Table_A relationships.ini
[Store_Items]
__sql__ = "SELECT * FROM Table_C c INNER JOIN Table_B b ON c.item_id = b.item_id WHERE c.store_id = '$store_id'"

-------------------------------------

The data inserted/updated for the relationship via Table_A is being executed successfully.. but..
when viewing single item via Table_A related data listing, xataface created a tab that shows the relationship data from Table_C with the tab title "Untitled Table_C Record"

how can i make this tab disappear or hide this tab (tab-0) since i think it's unnecessary for the end-user to know about the table joins..

thanks in advance! :)


Steve Hannah

unread,
Dec 30, 2014, 12:56:15 AM12/30/14
to xata...@googlegroups.com
You can hide the relationship by adding action:condition="0"  or action:condition="false" to the relationship definition in the relationships.ini file.
You can also customize the record title by implementing a getTitle() method in the table c delegate class (that returns a title) so that it doesn't say "Untitled Table_C Record".

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/5170ecfe-914d-43c9-8485-703cf76571b2%40googlegroups.com.



--
Steve Hannah
Web Lite Solutions Corp.

Zack Hayato

unread,
Dec 31, 2014, 7:30:10 PM12/31/14
to xata...@googlegroups.com
Hi, Steve.. Happy New Year!

thanks for your answer but i found another workaround for it.. i've added another field in Table_C (Table_C.ref) and use title=1 in Table_C fields.ini..
but, i'm facing another issue here.. :(

Table_C has foreign keys that point back to Table_A & Table_B so that when the rows in Table_A & Table_B is being updated/deleted, the related rows in Table_C will also get updated/deleted (for data consistency)..

when i update/delete the data in Table_A & Table_B, xataface gave me a blank screen but the affected rows in the database is being updated/deleted correctly/accordingly.. i turn on PHP display errors in php.ini and got 3 PHP fatal error messages (pressing 'back' 3 times in the browser makes me realized there are 3 errors)..

1st error -> function field() called on non-object
2nd and 3rd error -> function hasJoinTable() called on non-object

so, Steve.. how can i get the foreign keys to work in xataface? (since it's working on the DB side)
FYI, i'm using the latest version of xataface (2.1.2)..


thanks in advance! :)

Zack Hayato

unread,
Dec 31, 2014, 7:42:56 PM12/31/14
to xata...@googlegroups.com

i suspect that the 1st error [field() called on non-object] is coming from the new field i added in Table_C (Table_C.ref) is not being set as a primary key..
as for the 2nd and 3rd error [hasJoinTable() called on non-object], i suspect it came from the __sql__ statement in relationships.ini on Table_A..
Table_C.ref is actually Table_A.store_name
so the __sql__ looks like this:

__sql__ = "SELECT * FROM Table_C c INNER JOIN Table_B b ON c.item_id = b.item_id WHERE c.store_id = '$store_id' and c.ref = '$store_name'"

hope my explanations will assist you in addressing the issue, Steve..
Message has been deleted
Message has been deleted

Zack Hayato

unread,
Dec 31, 2014, 8:23:09 PM12/31/14
to xata...@googlegroups.com

here's the exact PHP errors, Steve..

1st error = Fatal error: Call to a member function fields() on a non-object in C:\Inetsvr\www\xataface\
Dataface\RecordView.php on line 31
2nd and 3rd error = Fatal error: Call to a member function hasJoinTable() on a non-object in C:\Inetsvr\www\xataface\Dataface\FormTool.php on line 1037

and FYI too..
Table_A's fields.ini is using a custom __sql__ query:

__sql__ = "select a.*, b.tot_items from Table_A a inner join Table_A_view v on a.store_id = v.store_id"

-------

Table_A_view's select statement in the DB:

select a.store_id,
(select count(c.item_id) from Table_C c where c.store_id = a.store_id) as tot_items
from Table_A a

-------

now, i'm not sure whether the errors are coming from the __sql__ parameter in Table_C's relationships.ini or the __sql__ parameter in Table_A's fields.ini..
hmm...

any idea, Steve?


Steve Hannah

unread,
Jan 2, 2015, 11:41:03 AM1/2/15
to xata...@googlegroups.com
These errors typically happen when the found set is empty.   What is the URL query string when these errors appear?  (e.g. -table and -action parametesr).

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.

Skinny Guy

unread,
Jan 2, 2015, 6:57:09 PM1/2/15
to xata...@googlegroups.com
Hi, Steve.. it's OK now.. i've sorted things out..

it seems like having more than 1 primary keys in the main tables (Table_A & Table_B) gave me those errors..
previously i've set Table_A.store_id and Table_A.store_name as the primary keys.. i change the store_name to a unique key, there's no error when i update/delete the main tables and the relationships data also being updated/deleted accordingly..

guess i need to learn more about xataface.. :)
You received this message because you are subscribed to a topic in the Google Groups "Xataface" group.
Reply all
Reply to author
Forward
0 new messages