Lookup widget on view with compound primary key
Archived from the Xataface Users forum.
ADobkin — Sun Apr 15, 2012 7:38 am
I have encountered an interesting situation with one of my tables. I have a view which requires a compound primary key. It is a table based on a calendar with repeating events. The view itself works fine in Xataface.
In another table, I am using a lookup widget to pick dates from the view. They show up correctly in the lookup widget list, but they were not being saved to the database. I was using an INT field to save the ID, but they were all saved as 0, so I changed it to VARCHAR to see if it would display a text value.
As it turns out, this is what is being stored in the database for this field:
tablename_view?keyid1=XX&keyid2=XX (where XX is replaced by the actual ID numbers)
Is this normal? I wasn’t sure quite what to expect here, but if I leave this field set to VARCHAR, it does work properly now.
shannah — Sun Apr 15, 2012 10:11 am
Yes. This is not documented but is normal. The lookup widget will return the value of the primary key for the id if there is a single column primary key. If there is a multi-column primary key, it instead returns the Xataface unique record id. Xataface record Ids are in the format
tablename?key1=val1&key2=val2
The Xataface API has a number of functions designed to deal with this type of ID, and it’s relatively easy to parse if you need a particular key value.
-Steve
ADobkin — Sun Apr 15, 2012 10:21 am
Perfect, thanks! I will add a pointer to this post in the wiki.