Display concat fields in relationship

A place for users and developers of the Xataface to discuss and receive support.

Display concat fields in relationship

Postby lenah » Thu Mar 25, 2010 10:15 am

Greetings,

First of all, I want to say that Xataface is awesome! It's very flexible and provides so many options for customization. Bravo!

Now the question: I have a many-to-many relationships between two tables (person and assignment) and an associative table to store the relationship (person_assignment). Here is the simified table structure:
person(pid, firstname, lastname)
assignment(aid, description)
person_assignment(pid,aid)

I defined the relationship in my assignment folder using SQL and the relationship tab works fine.

In the details>edit tab, I use checkbox to allow users to assign the current assignment to multiple people. Currently, the field value for the checkbox is the person's first name. Is it possible to have a concat field value, such as concat(lname, " ", fname)?

Thanks!

Lena
lenah
 
Posts: 4
Joined: Thu Mar 25, 2010 9:59 am

Re: Display concat fields in relationship

Postby shannah » Thu Mar 25, 2010 10:54 am

If you implement the getTitle() method on the target table of the relationship to display both names, that should do the job:

Code: Select all
function getTitle(&$record){
    return $record->val('fname').' '.$record->val('lname');
}
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Display concat fields in relationship

Postby lenah » Thu Mar 25, 2010 12:38 pm

Hello Steve,

Thanks for your prompt reply. I have tried your solution. The field names are concatenated in the person tab but the checkboxs in assignment tab still display only the first name :(

This is how I declared my personname field in fields.ini in assignment folder:
[personname]
widget:type=checkbox
transient=1
relationship=personassignment

I declared personassignment in my relationships.ini:
[personassignment]
__sql__ = "SELECT * FROM person_assignment pa JOIN person p ON pa.pid = p.pid WHERE pa.aid = '$aid'"

I tried implemeting a delegate class on my assignment tab
<?php
class tables_assignment {
function personname__display(&$record){
return $record->val('firstname').' '.$record->val('lastname');
}
}
?>
But it still doesn't work :(
lenah
 
Posts: 4
Joined: Thu Mar 25, 2010 9:59 am

Re: Display concat fields in relationship

Postby shannah » Thu Mar 25, 2010 12:49 pm

So your relationship goes from the assignment table to the people table (i.e. it is showing the people that are related to a certain assignment).

Your getTitle() method should be defined in the people delegate class.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Display concat fields in relationship

Postby lenah » Thu Mar 25, 2010 1:03 pm

This is my person.php
<?php
class tables_person {
function getTitle(&$record){
return $record->val('firstname').' '.$record->val('lastname');
}
}
?>

The title of the record does change to include both last name and first name but the field display of the check box does not :|
lenah
 
Posts: 4
Joined: Thu Mar 25, 2010 9:59 am

Re: Display concat fields in relationship

Postby shannah » Thu Mar 25, 2010 1:14 pm

OK.. it is possible that this is a case where you need to use the titleColumn() method instead.

The titleColumn has the same effect as getTitle() (it customizes the columns you mean to use as the title for a record). The difference is that titleColumn() is used when obtaining the title on an entire set of records without having to load the whole record into memory. It uses a different syntax also as it is meant to assist in SQL queries.

e.g.

Code: Select all
function titleColumn(){
    return "concat(firstname,' ',lastname)";
}


It should return a string that can be used as a column identifier in the select clause of an SQL query.

(This method goes in your people delegate class).

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Display concat fields in relationship

Postby lenah » Thu Mar 25, 2010 1:20 pm

Hello Steve,

Thank you so much! It works like a charm!

Cheers,
Lena
lenah
 
Posts: 4
Joined: Thu Mar 25, 2010 9:59 am


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 25 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved