question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Focuspoint with Eager Loading

See original GitHub issue

Hi,

I’m using eager loading for retrieving some images for my gallery:

{% set employments = craft.entries({ section: 'employments', with: ['photo] }) %}

This works fine and I can see all images on my page. But whenever I try to get the focuspoints of that image:

photo[0].focusPctX All images have the same focuspoints (50).

Whenever I try to retrieve the images without the Eager Loading function, it works fine.

Is this a known ‘bug’, or is Eager Loading just not supported by Focuspoint?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
aaronwaldoncommented, Sep 13, 2017

I know I’m a little late, but I was able to get eager loading to work with Focus Point by adding the following method in FocusPoint_AssetElementType.php:

	/**
	 * Adds the focusX and focusY points to the row that populates the model. This
	 * allows the focus point to still work with eager loading.
	 * 
	 * @param DbCommand $query
	 * @param ElementCriteriaModel $criteria
	 */
	public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria)
	{
		$query
			->addSelect('ff.focusX, ff.focusY')
			->leftJoin('focuspoint_focuspoints ff', 'ff.assetId = elements.id');

		parent::modifyElementsQuery($query, $criteria);
	}

Hope that helps! Just added a pull request: #18

0reactions
terryuptoncommented, Apr 26, 2018

I am having issues with Eager Loading still. See these posts. aelvan/Imager-Craft#168 (comment) and #22

I am still trying to get to the bottom of it and understand exactly what is causing this to fallover, it seems as though it is getting a value from a previous asset or something?

Digging a little deeper into the database, I noticed two rows for the same asset.

****id**
10813

**assetId**
1988

**fieldId**
31

**focusX**
0.07

**focusY**
0.17

**sourceId**
1989

**dateCreated**
2018-04-26 20:24:39

**dateUpdated**
2018-04-26 20:24:39

**uid**
6bfbb940-d66e-418d-b211-6dfa6676acd3


****id**
5604

**assetId**
1988

**fieldId**
9

**focusX**
0.01

**focusY**
-0.04

**sourceId**
1989

**dateCreated**
2018-03-03 13:52:24

**dateUpdated**
2018-03-03 13:52:24

**uid**
f68806d6-e332-4881-b5ce-014fe2159571

I am wondering if with this fix, it is in-fact getting/selecting the wrong FocusPoint, where it has been used for a different field. Is there a way to extend this to match the right field ID?

I might be wrong in my assumption, but my PHP isn’t strong enough to test or resolve.

Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Correctly using eager loading in Plugin development
Eager loading only works when your field is a RelationField it does not work with Text fields. If you goal is to reduce...
Read more >
Speed up your Craft CMS Templates with Eager Loading
Eager -Loading Elements allows you to speed up your Craft CMS templates by fetching entries from the database more efficiently.
Read more >
Training and Tutorials for Craft CMS
Eager-loading elements gives you the ability to tell Craft which sub-elements you need up ... Focuspoint lets you select a focal point of...
Read more >
Focus point selection - Canon EOS - Photo.net
I recently purchased a Mk IV and find the default AF Point Selection (the [ ] button on the back, to the right...
Read more >
Am I doing eager loading correctly? (Eloquent) - Stack Overflow
user') it loads both the entrants and the user once you get to ->get() . When you do ->load('user') it runs another query...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found