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

Fix raw row fetching issue with composite keypaths and custom classes #1015

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hprange
Copy link
Contributor

@hprange hprange commented Oct 23, 2023

This pull request addresses an issue that occurs when you attempt to retrieve raw rows using composite keypaths where the last element is associated with a custom class.

To illustrate the problem, consider the following example:

erDiagram
    Post {
        long id
        long fk_author
    }

    User {
        long id
        Enum gender
    }

    Post |{--|| User : author
Loading

In this scenario, User is the target of the author relationship defined by Post. The gender attribute of User uses a custom class, such as one defined by the javaEnum prototype.

The issue arises when you use the following code:

var fs = new ERXFetchSpecification<Post>(Post.ENTITY_NAME);
fs.setFetchesRawRows(true);
fs.setRawRowKeyPaths(Post.AUTHOR.dot(User.GENDER).key());
fs.fetchObjects(ec);

The result of this operation is an NSArray of NSDictionary where the "author.gender" key returns an object of type NSData, rather than the expected Enum type.

This behavior occurs because the EOAttribute constructor is called with the entity and definition parameters when fetching composite keypaths using raw rows. During EOAttribute initialization, the composite keypath is resolved, and the resulting EOAttribute behaves as if it were the referenced attribute. However, this only happens if the attribute is flattened. Otherwise, the EOAttribute is not fully initialized, and the JDBCColumn is unable to convert the returned data from the database to the correct type.

To resolve this issue, I've made changes to ensure that attribute properties are initialized correctly, even if the attribute is not flattened.

I've thoroughly tested this change on a large application, covering both normal and raw rows fetching, and I couldn't find any issues so far. While I don't anticipate any problems arising from these changes, I would appreciate feedback from others on this matter.

@hprange hprange self-assigned this Oct 23, 2023
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

Successfully merging this pull request may close these issues.

1 participant