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

Nested include directives return all default includes of ORM Entity relationships #37

Open
stoked74 opened this issue Jun 14, 2023 · 9 comments

Comments

@stoked74
Copy link

What are the steps to reproduce this issue?

  1. Define a nested relationship in the defaultIncludes or a profile array e.g. "role.id"

What happens?

The entire role memento is returned. (this.memento is also defined on the role object)

What were you expecting to happen?

I'm expecting an object that only contains the id property.

{id: 1}

Any logs, error output, etc?

No

Any other comments?

In my case role is a hibernate relationship. I am using CBORM. Setting ormAutoIncludes true or false doesn't seem to make a difference.

What versions are you using?

ACF 2021 (most recent patch)
Mementifier 3.3.1+37

@lmajano
Copy link
Contributor

lmajano commented Jun 14, 2023

I need you to add your sample code and the way you are running getMemento(). If not, it's impossible to debug my friend

@stoked74
Copy link
Author

Here you go.

I have an ORM object that has a m-1 relationship and it's memento defined like this.

AssociatedGarage.cfc (all of the standard props are excluded for brevity)

// m-1
property name="garage" fieldtype="many-to-one" cfc="models.garage.Garage" fkcolumn="garageId" fetch="join";

this.memento = {
    defaultIncludes: [
      "id",
      "notes",
      "garage.id"
      ]
  };

I'm running an HQL query and then looping over the result and calling getMemento() on each object individually.

var associatedGarages = ormService.executeQuery("from AssociatedGarage ag where ag.user.id = :userId order by ag.garage.number", {userId: rc.user.id});

prc.data = associatedGarages.map(function(d) {
      return d.getMemento();
    });

event.getResponse().setData({associatedGarages: prc.data});

@lmajano
Copy link
Contributor

lmajano commented Jul 3, 2023

Will get on this and test away

@lmajano
Copy link
Contributor

lmajano commented Sep 18, 2023

Ok, do you happen to have ormAutoIncludes = true in your settings? This is the default. So if that's on, then ALL properties are defaulted for output.

@lmajano
Copy link
Contributor

lmajano commented Oct 20, 2023

@stoked74 Did you see my message.

If you have auto orm includes then it will try to auto include all properties for all ORM entities that have NO default includes.

You posted your default includes for the AssociatedGarage entity, but not for the Garage entity.

@jclausen
Copy link
Contributor

This is still an issue and also applies to Lucee. ormAutoIncludes only defaults to simple value properties, but it may be getting in the way of returning only the keys requested.

@jclausen jclausen changed the title Nested includes don't work in ACF 2021 Nested include directives return all default includes of ORM Entity relationships Oct 25, 2023
@homestar9
Copy link
Contributor

homestar9 commented Dec 14, 2023

@lmajano Came here to report I am seeing the same behavior when using Quick entities as well.

this.memento.defaultIncludes = [ "id", "categoryId", "category.name" ]

The above code returns the entire category memento, and not just category.name.
Quick, by default, has ormAutoIncludes set to false.

It also happens when using memento profiles as well, just in case that is important information.

@lmajano
Copy link
Contributor

lmajano commented Dec 15, 2023

I can't replicate this can ypou assist me @homestar9

@homestar9
Copy link
Contributor

Yes, I will try to assemble a sample repo to help replicate the issue.

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

No branches or pull requests

4 participants