Page 1 of 1

Dropbox box wrong when adding existing records

PostPosted: Tue Jan 31, 2012 11:07 am
by titleistfour
Hello,

I have a curious issue that I hope someone can offer some advice on.

I'm working with several related tables. When I go to the related field tab under a topic, and select "Add an existing <table> record", Xataface builds a dropdown box of those existing related fields that I can choose from. My dropdown box is being populated with the 'creator' field of that existing record. I would prefer that it be created with the 'number' field. The weird thing I noticed was that if I change the 'number' field to be varchar instead of int, then it populates correctly. Is this expected behavior? Can I control how that dropdown gets populated? How does Xataface figure out which field is used to populate that dropdown box?

This is the table I'm working with. Pretty simple stuff.

CREATE TABLE `letters` (
`letter_id` int(11) NOT NULL auto_increment,
`number` int(6) NOT NULL,
`description` text NOT NULL,
`creator` varchar(10) default NULL,
`date_created` datetime default NULL,
`date_modified` datetime default NULL,
PRIMARY KEY (`special_letter_id`),
UNIQUE KEY `number` (`number`)
)

Thanks,
Jay

Re: Dropbox box wrong when adding existing records

PostPosted: Tue Jan 31, 2012 11:13 am
by shannah
Xataface displays what it thinks is the record's title in the drop box. If you don't explicitly tell it which field is the "title" it will make a best guess. It's "best guess" algorithm is crude... it essentially just takes the first varchar field.

Solution: implement the titleColumn() and getTitle() methods in the target table.
titleColumn() returns a column name (it is used when returning a full set of records so that it doesn't have to load the whole record in order to determine the title.
getTitle() takes a Dataface_Record object as a parameter and returns the title of the record as a string. It is used when a single record is already loaded.

e.g.
Code: Select all
function titleColumn(){
    return 'number';
}
function getTitle($record){
   return $record->val("number");
}


Note that titleColumn() allows you to use SQL expressions like CONCAT() also.. you're not limited to a single column.

Re: Dropbox box wrong when adding existing records

PostPosted: Tue Jan 31, 2012 11:30 am
by titleistfour
Steve that worked perfectly! Thank you

Sure wish you guys had some type of donation fund setup, I think I'm racking up enough of your time to warrant that :-)

Jay