Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Innacurate relationships showing in Craft 3.9.10 #26

Open
stevehurst opened this issue Jan 16, 2024 · 7 comments
Open

Innacurate relationships showing in Craft 3.9.10 #26

stevehurst opened this issue Jan 16, 2024 · 7 comments

Comments

@stevehurst
Copy link

We're seeing some entries related to each other where there is no actual relation. The entries in question share some Title and Slug similarities with other entries that are related, but they have unique entry IDs, so should not be showing in the list.

I don't know how to detail this issue further. Please let me know what level of detail you would need to support.

@reganlawton
Copy link
Member

@stevehurst I think I might need abit information.

  • Some info would be what try of object is being Lin led wrong (entry, category, user, etc)?
  • Is it linked in a matrix somewhere?
  • etc

Basically some images might be useful too I really need to found out HOW to cause the "bug".

@stevehurst
Copy link
Author

@reganlawton

Both objects are entries, one is a structure and the other a channel.

We're using matrix fields to relate these using a standard "Entries" field within the block.

In my screenshots below, you'll see two Case Studies entries, with the same naming structure, but one is for "Water Conservartion", the other for "Mining". Both show a relationship to the two Services entries "Sustainability" and "Autonomous Manufacturing", but in reality only the "Water Conservation" Case Study entry is related via a Matrix field. The "Mining" Case Study isn't related in any way. One of my Services entries ("Sustainability") doesn't even show the Case Study that is really related ("Water Conservation").

Screenshot 2024-01-16 at 7 40 33 PM Screenshot 2024-01-16 at 7 40 43 PM Screenshot 2024-01-16 at 7 41 10 PM Screenshot 2024-01-16 at 7 41 47 PM

@reganlawton
Copy link
Member

The whole plugin uses relatedTo which is a CraftCMS feature via the ORM. As seen in the below code.

/** @var Element $element */
$element = Craft::$app->elements->getElementById($elementId);
/** @var Element $elementType */
$elementType = Craft::$app->elements->getElementTypeById($elementId);

$query = MatrixBlock::find()->site($selectedSite);
$query->relatedTo = $element;
$query->anyStatus();
/** @var MatrixBlock[] $blocks */
$blocks = $query->all();

$matchingBlocks = [];
foreach ($blocks as $block) {
    $owner = $block->getOwner();
    if ($owner) {
        $matchingBlocks[$owner->id] = $owner;
    }
}

/** @var Query $query */
$query = Entry::find()->site($selectedSite);
$query->relatedTo = $element;
$query->anyStatus();
/** @var Element[] $entries */
$entries = $query->all();

The relationship has been picked up in the system. I'm wondering you need to rebuild the search and cache 🤔

@stevehurst
Copy link
Author

stevehurst commented Jan 17, 2024 via email

@reganlawton
Copy link
Member

I believe it might be in setting and be called "Rebuild Search Indexes" and "Clear Caches" -> "Data caches" I'm not 100% sure where the relatedTo gets its data from without looking under the hood but it could be a good start.

If not, I'm convinced it's linked somehow.

@stevehurst
Copy link
Author

stevehurst commented Jan 19, 2024 via email

@reganlawton
Copy link
Member

I'm glad to hear! 🙌

You can do it via Craft CLI I believe and set up a cronjob.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants