File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -685,6 +685,9 @@ public function load(Model $model)
685685 */ 
686686class  BelongsTo extends  AbstractRelationship
687687{
688+ 
689+ 	static  protected  $ valid_association_optionsarray ('primary_key ' );
690+ 
688691	public  function  __construct ($ optionsarray ())
689692	{
690693		parent ::__construct ($ options
@@ -695,6 +698,9 @@ public function __construct($options=array())
695698		//infer from class_name 
696699		if  (!$ this foreign_key )
697700			$ this foreign_key  = array (Inflector::instance ()->keyify ($ this class_name ));
701+ 
702+ 		if  (!isset ($ this primary_key ) && isset ($ this options ['primary_key ' ]))
703+ 			$ this primary_key  = is_array ($ this options ['primary_key ' ]) ? $ this options ['primary_key ' ] : array ($ this options ['primary_key ' ]);
698704	}
699705
700706	public  function  __get ($ name
Original file line number Diff line number Diff line change @@ -165,6 +165,19 @@ public function test_belongs_to_with_explicit_foreign_key()
165165		Book::$ belongs_to$ old
166166	}
167167
168+ 	public  function  test_belongs_to_with_explicit_primary_key ()
169+ 	{
170+ 		$ old$ belongs_to
171+ 		Book::$ belongs_toarray (array ('explicit_author ' , 'class_name '  => 'Author ' , 'primary_key '  => 'parent_author_id ' ));
172+ 
173+ 		$ bookfind (1 );
174+ 		$ this assert_equals (1 , $ bookauthor_id );
175+ 		$ this assert_equals (1 , $ bookexplicit_author ->parent_author_id );
176+ 		$ this assert_equals (3 , $ bookexplicit_author ->author_id );
177+ 
178+ 		Book::$ belongs_to$ old
179+ 	}
180+ 
168181	public  function  test_belongs_to_with_select ()
169182	{
170183		Event::$ belongs_to0 ]['select ' ] = 'id, city ' ;
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments