cakephp-image icon indicating copy to clipboard operation
cakephp-image copied to clipboard

Association property name is wrong when the model is fetched with a Contain

Open lorro opened this issue 7 years ago • 3 comments

Hi,

I noticed the following strange behaviour. In my specific use case I have a 'Users' model with uses the Image behavior with an "image" field 'fields' => ['image' => 'one']

When I fetch a user directly in the database I get the following data which is how it should be.

object(App\Model\Entity\User) {
	'id' => (int) 1,
	'first_name' => 'Laurent',
	'language' => 'nl',
	'image' => object(Cake\ORM\Entity) {
		'id' => (int) 1,
		'field_index' => (int) 0,
		'model' => 'Users',
		'foreign_key' => (int) 1,
		'field' => 'image',
		'filename' => '31f81b83a1aad2d8c70a0d8f09627063.jpg',
		'size' => (int) 85992,
		'mime' => 'image/jpeg',
	}
    }

But when I try to fetch a user by a related model the naming of the propertyName is different. $customer = $this->Customers->get($id, ['contain' => ['Notes' => ['Users' => ['fields' => ['id', 'full_name']]]]]);

In my case users can write notes about customers, and when I try to fetch the author of a note, I get the following result.

'author' => object(App\Model\Entity\User) {
	'id' => (int) 1,
	'first_name' => 'Laurent',
	'image_image' => object(Cake\ORM\Entity) {
		'id' => (int) 1,
		'field_index' => (int) 0,
		'model' => 'Users',
		'foreign_key' => (int) 1,
		'field' => 'image',
		'filename' => '31f81b83a1aad2d8c70a0d8f09627063.jpg',
		'size' => (int) 85992,
		'mime' => 'image/jpeg'
	}
}

It seems in this case the Behavior doesn't enter the mapReduce function in the beforeFind callback. Any chance you could get a look into this?

Thanks!

lorro avatar Mar 23 '17 16:03 lorro

This plugin seems dead, have not got any reply from the person develop this...

tgoeminne avatar Mar 29 '17 05:03 tgoeminne

Yes, I already had the same impression ;) But I just opened these issues, just in case someone else decides to pick this repo up :)

lorro avatar Apr 01 '17 12:04 lorro

Sorry for the late reply :-) Could you maybe create a PR with a fix?

josbeir avatar Jun 15 '18 09:06 josbeir