| How to provide choices for two compound foreign keys in a form? [message #4853] | 
			Tue, 21 July 2015 21:15   | 
		 
		
			
				
				
				
					
						  
						rafs
						 Messages: 69 Registered: May 2015 
						
					 | 
					Member  | 
					 | 
		 
		 
	 | 
 
	
		I have a list1 for families, a list1 for variants. 
I have a link1 from families to variants; and a link1 from variants to families. 
families --< families_variants >-- variants 
famiilies_variants only has (family_name, variant_name) as PK, with each field also being a FK to the parent tables. 
This part is working fine. 
 
Now, I have a table called lines, and a line is has a compound foreign key linking it to families_variants. 
So, 
 
lines 
----- 
line_id 
line_text 
... 
family_name 
variant_name 
 
The question is, when filling in the New 'line' form, how to best go about providing the user with a method to select a combination of (family_name, variant_name) from the available entries in families_variants? 
It would be good to allow them to choose a family_name, and then choose the available variant_names, or (bonus) if they could choose variant_name first, then choose the available families. 
 
 
		
		
		
 |  
	| 
		
	 | 
 
 
 | 
	| 
		
 | 
	| 
		
 | 
	
		
		
			| Re: How to provide choices for two compound foreign keys in a form? [message #4856 is a reply to message #4855] | 
			Thu, 23 July 2015 07:18    | 
		 
		
			
				
				
				
					
						  
						AJM
						 Messages: 2386 Registered: April 2006  Location: Surrey, UK
						
					 | 
					Senior Member  | 
					 | 
		 
		 
	 | 
 
	
		This is what I have in the _cm_initialise() method of the parent entity in the POPUP2 task: 
$pattern_id = getPatternId();
if (!preg_match('/order_id=/i', $where)) {
    if (isset($GLOBALS['return_from'])) {
        if ($GLOBALS['return_from'] == 'ord_order_header_p(popup1)') {
            // nothing selected from popup screen, so exit now
            scriptPrevious($GLOBALS['errors']);
        } // if
    } // if
    if (preg_match('/popup2/i', $pattern_id)) {
        // order_id has not been supplied yet, so get it now via a popup
        scriptNext('ord_order_header_p(popup1)', $where);
    } // if
} // if
 
It is expecting to find "order_id=...." in the $where string. If it isn't there it suspends the current task and executes the popup which will provide a value for order_id. If this popup is terminated without choosing a value then this task will quit and return to the task which called it.
		
		
  Tony Marston 
http://www.tonymarston.net 
http://www.radicore.org
		
 |  
	| 
		
	 | 
 
 
 | 
	| 
		
 | 
	
		
		
			| Re: How to provide choices for two compound foreign keys in a form? [message #4939 is a reply to message #4938] | 
			Thu, 27 August 2015 05:47   | 
		 
		
			
				
				
				
					
						  
						AJM
						 Messages: 2386 Registered: April 2006  Location: Surrey, UK
						
					 | 
					Senior Member  | 
					 | 
		 
		 
	 | 
 
	
		You need to look at the code in the _cm_initialise() method of the parent entity in the POPUP2 task. If the $where string contains something that identifies an entry on that table then continue, otherwise jump to a POPUP1 task to allow the user to select an entry. 
 
This means that when calling the POPUP2 task and you already have a value for the parent entity which you want to use then this value must be included in the $where string which is passed to the POPUP2 task.
		
		
  Tony Marston 
http://www.tonymarston.net 
http://www.radicore.org
		
 |  
	| 
		
	 | 
 
 
 |