Snog
Well-known member
This is driving me nuts. I can't seem to pull the XF user entity directly into a query result.
My entity:
	
	
	
		
The PHP code for the finder:
	
	
	
		
The print_r result from PHP:
	
	
	
		
I would expect the relation to be in that print_r dump. Yes? No?
It is there with other similar relations I've done, but for some reason this one... nadda.
If I do a loop through and then request the User relation it does show up there if I request it with.
	
	
	
		
But I'm thinking it's doing a database query each time (not checked).
				
			My entity:
		Code:
	
	public static function getStructure(Structure $structure)
{
    $structure->table = 'xf_snog_addon_users';
    $structure->shortName = 'Snog\Addon:User';
    $structure->primaryKey = 'user_id';
    $structure->columns = [
        'user_id' => ['type' => self::UINT],
        'myfield' => ['type' => self::SERIALIZED_ARRAY, 'default' => []]
    ];
    $structure->getters = [];
    $structure->relations = [
        'User' => [
            'entity' => 'XF:User',
            'type' => self::TO_ONE,
            'conditions' => 'user_id',
            'primary' => true
        ],
    ];
    return $structure;
}The PHP code for the finder:
		Code:
	
	$users = $this->finder('Snog\Addon:User')
        ->with('User')
        ->where('myfield', 'LIKE', $fieldSearch)
        ->fetch();The print_r result from PHP:
		Code:
	
	XF\Mvc\Entity\ArrayCollection Object
(
    [entities:protected] => Array
        (
            [1] => Snog\Addon\Entity\User Object
                (
                    [_uniqueEntityId:XF\Mvc\Entity\Entity:private] => 4
                    [rootClass:protected] => Snog\Addon\Entity\User
                    [_newValues:protected] => Array
                        (
                        )
                    [_values:protected] => Array
                        (
                            [user_id] => 1
                            [myfield] => a:2:{i:0;s:1:"1";i:1;s:1:"2";}
                        )
                    [_relations:protected] => Array
                        (
                        )
                    [_previousValues:protected] => Array
                        (
                        )
.....
)I would expect the relation to be in that print_r dump. Yes? No?
It is there with other similar relations I've done, but for some reason this one... nadda.
If I do a loop through and then request the User relation it does show up there if I request it with.
		Code:
	
	foreach ($users as $user)
{
      print_r($user->User);
}But I'm thinking it's doing a database query each time (not checked).
			
				Last edited: 
			
		
	
								
								
									
	
								
							
							 
 
		 
 
		
 
 
		 
 
		 
 
		 
 
		 
 
		