A place for users and developers of the Xataface to discuss and receive support.
by 00Davo » Thu Jan 07, 2010 6:03 pm
This isn't really a problem with Xataface, but any assistance would be most welcome. I've set up a category checkbox system for one of my tables, almost exactly as described in method 3 here.Now I want to implement the relationships to that table in a very specific way. I've got two relevant relationship tabs, both of which are many-to-many. I'd like these tabs to only be accessible (and, conversely, the record to only appear on the other end of the relationship) if a specific category is selected in the aforementioned category system (different category for each tab). I just can't figure out the SQL for such a query. 
-
00Davo
-
- Posts: 55
- Joined: Sat Jan 02, 2010 9:02 pm
by shannah » Mon Jan 11, 2010 11:57 am
One nice way to hide/show a relationship tab conditionally is using the action:condition attribute of the relationship in the relationships.ini file. Here is an example: - Code: Select all
[courses_taught] __sql__ = "select * from courses where instructor='$person_id'" action:condition = "!in_array($record->val('category'), array(8,9,11))" action:label = "Courses (Instructor)"
[courses_tad] __sql__ = "select * from courses c inner join course_tas as ct on c.course_id=ct.course_id where ct.person_id='$person_id'" action:condition = "!in_array($record->val('category'), array(1,4,5,6,11))" action:label = "Courses (TA)"
I have 2 relationships here in the people table. If the current record (person) is a teacher, I want the courses_taught relationship to show up. If the current record (person) is a grad student, I want the courses_tad to show up (i.e. the course that they are teaching assistants for). You can see the action:condition directive that checks the category of the current person to see if they are in the appropriate category.
-
shannah
-
- Posts: 4457
- Joined: Wed Dec 31, 1969 5:00 pm
by 00Davo » Thu Jan 14, 2010 6:57 pm
Thanks for the assistance, as always  - this solves exactly half the problem. The other half of the problem: it's a many-to-many relationship, and you can add records from either "end". Adding this condition (to my Adult table) prevents me from adding a class to a non-tutor adult (perfect!), but I can go to the class, and add the adult from there with Add Existing Record (not so perfect). What do I need to do to fix this bit? Ideally, the existing-record list on the Class end would only display adults that satisfy the condition. 
-
00Davo
-
- Posts: 55
- Joined: Sat Jan 02, 2010 9:02 pm
by shannah » Thu Jan 14, 2010 10:18 pm
You can customize the list of records that can be added to a relationship via the add existing dialog, by either by specifying the 'vocabulary:existing' directive in the relationship defintion, or by defining the {relationshipname}__getAddableValues() in your delegate class. Defining the vocabulary existing attribute might look as follows: valuelists.ini file: - Code: Select all
[my_addable_values] __sql__ = "select id, name from foo where can_be_added=1" [code]
relationships.ini file: [code] [my_relationship] __sql__ = "..." vocabulary:existing="my_addable_values"
-Steve
-
shannah
-
- Posts: 4457
- Joined: Wed Dec 31, 1969 5:00 pm
by 00Davo » Thu Jan 14, 2010 11:12 pm
Unfortunately, I'm having problems again, and need to ask for more help. I've implemented the files like this. relationships.ini: - Code: Select all
[Tutors] adult.AdultID = classes.AdultID classes.ClassID = "$ClassID" vocabulary:existing = "Tutors"
valuelists.ini - Code: Select all
[Tutors] __sql__ = "SELECT Adult.AdultID, CONCAT(LName, ', ', FName) FROM adult INNER JOIN AdultRole ON Adult.AdultID = AdultRole.AdultID AND AdultRole.RoleID = 3"
When I go to add a related record, I get PHP errors at the top: - Code: Select all
Warning: array_keys() expects parameter 1 to be array, null given in C:\xampp\xampp\htdocs\newypt\xataface\Dataface\Relationship.php on line 1255
Warning: Invalid argument supplied for foreach() in C:\xampp\xampp\htdocs\newypt\xataface\Dataface\Relationship.php on line 1255
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\xampp\htdocs\newypt\xataface\Dataface\Relationship.php:1255) in C:\xampp\xampp\htdocs\newypt\xataface\Dataface\Application.php on line 1603
And a Xataface error: - Code: Select all
Errors There are no records that can be added to this relationship.
If I run the same SQL query directly, it returns plenty of records. Additionally, if I use the valuelist in a more "traditional" manner, with fields.ini, it returns records just fine. It's just the relationship that won't work with my query. I'm having problems. Again. I'm not really very good at this stuff. 
-
00Davo
-
- Posts: 55
- Joined: Sat Jan 02, 2010 9:02 pm
by shannah » Thu Jan 14, 2010 11:25 pm
In which table's valuelists.ini file did you define the valuelist? And in which table's relationships.ini file did you define the relationship?
-
shannah
-
- Posts: 4457
- Joined: Wed Dec 31, 1969 5:00 pm
by 00Davo » Thu Jan 14, 2010 11:26 pm
shannah wrote:In which table's valuelists.ini file did you define the valuelist? And in which table's relationships.ini file did you define the relationship?
Whoops, sorry. Both are in the /tables/class folder.
-
00Davo
-
- Posts: 55
- Joined: Sat Jan 02, 2010 9:02 pm
by 00Davo » Thu Jan 14, 2010 11:49 pm
Experimentally, I copied the valuelist definition into /tables/adult/valuelists.ini, and it works now. So the destination has to define the valuelist, apparently. Anyway, it works. Yay. 
-
00Davo
-
- Posts: 55
- Joined: Sat Jan 02, 2010 9:02 pm
Return to Xataface Users
Who is online
Users browsing this forum: No registered users and 9 guests
|