set default value for 'add existing record'

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

set default value for 'add existing record'

Postby lemon dexter » Wed Nov 21, 2012 6:38 am

I'm having a problem setting a default value.

This will go into the 'utility' table of the many-to-many relationship. Using a default function in the table's delegate class, this works fine for the 'add new related' action, but not for the 'add existing', which stays blank.

Very grateful for any ideas.
lemon dexter
 
Posts: 23
Joined: Sat May 26, 2012 7:58 am
Location: Bristol, England

Re: set default value for 'add existing record'

Postby shannah » Fri Nov 30, 2012 4:08 am

Can you post a small test case that I can reproduce? E.g. Table def, relationship def, delegate default methods. etc...
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: set default value for 'add existing record'

Postby lemon dexter » Fri Nov 30, 2012 9:58 am

Thanks Steve - I've actually found another way around this - I wanted to set a filter on a depselect, but I've achieved it via a simple select and a valuelist set in the delegate class (which is a little more elegant as it happens with less data redundency). However, I still reckon there may be a bug which you may want to know about so happy to provide some background. Basically, attempting to set any default, even using a constant as a test, would not get picked up for the 'add exisiting'.

Anyway, here's the context: It's a record set for a parish baptism: par_bap is the 'event' header record, person is a table of individuals, and persontosource is an intermediate table (for 1-many). A person can be the subject of the baptism, the father or the mother, with most records having all three. The same people can play different roles in other events (like marriages).

Here are the three table defs (and a bit of data for each):

Code: Select all
CREATE TABLE IF NOT EXISTS `par_bap` (
  `event_id` varchar(9) NOT NULL DEFAULT '',
  `event_type` varchar(3) DEFAULT NULL,
  `Linker` varchar(7) DEFAULT NULL,
  `Country` varchar(3) DEFAULT NULL,
  `County` varchar(7) DEFAULT NULL,
  `Village_or_Town` varchar(39) DEFAULT NULL,
  `Church_or_Chapel` varchar(7) DEFAULT NULL,
  `Date_of_Baptism` varchar(11) DEFAULT NULL,
  `Numeric_Date` date DEFAULT NULL,
  `Date_of_Birth` varchar(11) DEFAULT NULL,
  `Date_Seen` varchar(10) DEFAULT NULL,
  `Otherinfo` varchar(210) DEFAULT NULL,
  `Publication` varchar(51) DEFAULT NULL,
  `Correspondent` varchar(288) DEFAULT NULL,
  `Notes` varchar(747) DEFAULT NULL,
  `CR_or_BT` varchar(2) DEFAULT NULL,
  PRIMARY KEY (`event_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table `par_bap`
--

INSERT INTO `par_bap` (`event_id`, `event_type`, `Linker`, `Country`, `County`, `Village_or_Town`, `Church_or_Chapel`, `Date_of_Baptism`, `Numeric_Date`, `Date_of_Birth`, `Date_Seen`, `Otherinfo`, `Publication`, `Correspondent`, `Notes`, `CR_or_BT`) VALUES
('PBA1', 'PBA', 'PR10', 'ENG', 'HEF', 'Abbey Dore', NULL, '13 Mar 1794', '1794-03-13', NULL, NULL, NULL, 'IGI 1992', '', NULL, NULL),
('PBA2', 'PBA', 'PR20', 'ENG', 'HEF', 'Abbey Dore', NULL, '07 Mar 1852', '1852-03-07', NULL, NULL, NULL, NULL, NULL, NULL, NULL),
('PBA3', 'PBA', 'PR30', 'ENG', 'HEF', 'Abbey Dore', NULL, '20 Apr 1856', '1856-04-20', NULL, NULL, NULL, 'IGI 1992', '', NULL, NULL),
('PBA4', 'PBA', 'PR40', 'ENG', 'HEF', 'Abbey Dore', NULL, '10 Jun 1858', '1858-06-10', NULL, NULL, NULL, 'IGI 1992', '', NULL, NULL),
('PBA5', 'PBA', 'PR50', 'ENG', 'HEF', 'Abbey Dore', NULL, '08 Apr 1860', '1860-04-08', NULL, NULL, NULL, 'IGI 1992', '', NULL, NULL),
('PBA6', 'PBA', 'PR60', 'ENG', 'HEF', 'Almeley', NULL, '20 Nov 1686', '1686-11-20', NULL, NULL, NULL, 'IGI 1992', '', NULL, NULL);


Code: Select all
CREATE TABLE IF NOT EXISTS `person` (
  `person_id` int(11) NOT NULL AUTO_INCREMENT,
  `Forenames` varchar(30) DEFAULT NULL,
  `Surname` varchar(15) DEFAULT NULL,
  `Personal_Reference` varchar(20) DEFAULT NULL,
  `Family_Reference` varchar(19) DEFAULT NULL,
  PRIMARY KEY (`person_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=11698 ;

--
-- Dumping data for table `person`
--

INSERT INTO `person` (`person_id`, `Forenames`, `Surname`, `Personal_Reference`, `Family_Reference`) VALUES
(1, 'John', 'BADHAM', 'Hef AbbeDo 1794a', 'B Hef AbbeDo 1794a'),
(2, 'Fanny', 'BADHAM', 'Hef AbbeDo 1852a', 'B Hef AbbeDo 1852a'),
(3, 'James', 'BADHAM', 'Hef AbbeDo 1856a', 'B Hef AbbeDo 1856a'),
(4, 'Thomas', 'BADHAM', 'Hef AbbeDo 1858a', 'B Hef AbbeDo 1856a'),
(5, 'Sarah Ann', 'BADHAM', 'Hef AbbeDo 1860a', 'B Hef AbbeDo 1856a'),
(6, 'William', 'BADHAM', 'Hef Almele 1686a', 'M Hef StreSu 1686a'),
(7, 'Charity', 'BADHAM', 'Hef Almele 1690a', 'M Hef StreSu 1686a'),
(8, 'Mary', 'BADHAM', 'Hef Almele 1731a', 'M Hef Almele 1730a'),
(9, 'John', 'BADHAM', 'Hef Almele 1733a', 'M Hef Almele 1730a'),
(10, 'Ann', 'BADHAM', 'Hef Almele 1735a', 'M Hef Almele 1730a'),
(11, 'Sarah', 'BADHAM', 'Hef Almele 1738a', 'M Hef Almele 1730a'),
(12, 'Elizabeth', 'BADHAM', 'Hef Almele 1745a', 'M Hef Almele 1730a'),
(13, 'Arthur', 'BADHAM', 'Hef Almele 1855a', 'M Hef Bredwa 1852a'),
(14, 'George', 'BADHAM', 'Hef Almele 1857a', 'M Hef Bredwa 1852a'),
(15, 'John', 'BADHAM', 'Hef Almele 1859a', 'M Hef Bredwa 1852a'),
(16, 'Elizabeth', 'BADDAM', 'Hef Ashper 1545a', 'B Hef Ashper 1545a'),
(17, 'Mary', 'BADAM', 'Hef Ashper 1723a', 'M Hef StokEd 1723a'),
(18, 'John', 'BADHAM', 'Hef Ashper 1724a', 'M Hef StokEd 1723a'),
(19, 'Richard', 'BADHAM', 'Hef Ashper 1747a', 'M Hef Ashper 1746a'),
(20, 'Thomas', 'BADHAM', 'Hef Ashper 1749a', 'M Hef Ashper 1746a');


Code: Select all
CREATE TABLE IF NOT EXISTS `persontosource` (
  `event_id` varchar(9) NOT NULL DEFAULT '',
  `person_id` int(5) NOT NULL DEFAULT '0',
  `event_type` varchar(3) NOT NULL DEFAULT '',
  `role_type` varchar(4) DEFAULT NULL,
  `evCountry` varchar(6) DEFAULT NULL,
  `evCounty_Area` varchar(7) DEFAULT NULL,
  `Occupation` varchar(25) DEFAULT NULL,
  `Residence` varchar(27) DEFAULT NULL,
  PRIMARY KEY (`event_id`,`person_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table `persontosource`
--

INSERT INTO `persontosource` (`event_id`, `person_id`, `event_type`, `role_type`, `evCountry`, `evCounty_Area`, `Occupation`, `Residence`) VALUES
('PBA1', 1, 'PBA', 'PBAS', 'ENG', 'HEF', NULL, NULL),
('PBA1', 4113, 'PBA', 'PBAF', 'ENG', 'HEF', NULL, NULL),
('PBA1', 8079, 'PBA', 'PBAM', 'ENG', 'HEF', NULL, NULL),
('PBA2', 2, 'PBA', 'PBAS', 'ENG', 'HEF', NULL, NULL),
('PBA2', 8080, 'PBA', 'PBAM', 'ENG', 'HEF', 'Servant', NULL),
('PBA3', 3, 'PBA', 'PBAS', 'ENG', 'HEF', NULL, NULL),
('PBA3', 4114, 'PBA', 'PBAF', 'ENG', 'HEF', 'Labourer', NULL),
('PBA3', 8081, 'PBA', 'PBAM', 'ENG', 'HEF', NULL, NULL),
('PBA4', 4, 'PBA', 'PBAS', 'ENG', 'HEF', NULL, NULL),
('PBA4', 4115, 'PBA', 'PBAF', 'ENG', 'HEF', NULL, NULL),
('PBA4', 8082, 'PBA', 'PBAM', 'ENG', 'HEF', NULL, NULL),
('PBA5', 5, 'PBA', 'PBAS', 'ENG', 'HEF', NULL, NULL),
('PBA5', 4116, 'PBA', 'PBAF', 'ENG', 'HEF', NULL, NULL),
('PBA5', 8083, 'PBA', 'PBAM', 'ENG', 'HEF', NULL, NULL),
('PBA6', 6, 'PBA', 'PBAS', 'ENG', 'HEF', NULL, NULL),
('PBA6', 4117, 'PBA', 'PBAF', 'ENG', 'HEF', NULL, NULL),
('PBA6', 8084, 'PBA', 'PBAM', 'ENG', 'HEF', NULL, NULL);


Here is par_bap's relationship.ini:

Code: Select all
[Persons]
person.person_id = persontosource.person_id
persontosource.event_id = "$event_id"


And the persontosource delegate default method, basically fetching a field from the 'parent' record:

Code: Select all
class tables_persontosource {

       function event_type__default(){
       $app =& Dataface_Application::getInstance();
       $currentrecord =& $app->getRecord();
       $evtype =& $currentrecord->getValue('event_type');
       return $evtype;

}


N.B I need this as a select operates on it to filter role types relating/restricted to the event type - par_bap is only one of many tables that will use the person table.

TIA
lemon dexter
 
Posts: 23
Joined: Sat May 26, 2012 7:58 am
Location: Bristol, England


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 28 guests

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