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

[bal persist] filter query by joined entity field not working in optimised queries #6543

Open
daneshk opened this issue May 16, 2024 · 0 comments

Comments

@daneshk
Copy link
Member

daneshk commented May 16, 2024

Description:
When we have something like below,

type Appointment record {|
    readonly int id;
    int doctorId;
    time:Civil appointmentTime;
    db:AppointmentStatus status;
    record {|
        int id;
        string name;
        string phoneNumber;
    |} patient;
|};

resource function get doctors/[int id]/appointments(int year, int month, int day) returns Appointment[]|error {
    return from Appointment appointment in dbClient->/appointments(targetType = Appointment)
        where appointment.doctorId == id &&
    appointment.appointmentTime.year == year &&
    appointment.appointmentTime.month == month &&
    appointment.appointmentTime.day == day
        select appointment;

}

It failed at runtime giving the below error

time=2024-05-15T16:04:59.294+05:30 level=ERROR module=ballerina/http message="unhandled error returned from the service" error={"causes":[],"message":"Error while executing SQL query: SELECT `Appointment`.`id` AS `id`,`Appointment`.`doctorId` AS `doctorId`,`Appointment`.`appointmentTime` AS `appointmentTime`,`Appointment`.`status` AS `status`,`patient`.`id` AS `patient.id`,`patient`.`name` AS `patient.name`,`patient`.`phoneNumber` AS `patient.phoneNumber` FROM `Appointment` AS `Appointment` LEFT JOIN `Patient` `patient` ON  `patient`.`id` = `Appointment`.`patientId` WHERE  Appointment.doctorId =  ?   AND appointmentTime.year =  ?   AND appointmentTime.month =  ?   AND appointmentTime.day =  ?  . Unknown column 'appointmentTime.year' in 'where clause'.","detail":{},"stackTrace":[{"callableName":"next","moduleName":"ballerinax.persist.sql.1.PersistSQLStream","fileName":"stream_types.bal","lineNumber":56},{"callableName":"process","moduleName":"ballerina.lang.query.0._InitFunction","fileName":"types.bal","lineNumber":141},{"callableName":"process","moduleName":"ballerina.lang.query.0._InputFunction","fileName":"types.bal","lineNumber":202},{"callableName":"process","moduleName":"ballerina.lang.query.0._FilterFunction","fileName":"types.bal","lineNumber":554},{"callableName":"process","moduleName":"ballerina.lang.query.0._SelectFunction","fileName":"types.bal","lineNumber":783},{"callableName":"$gen$$anon$method$delegate$_StreamFunction&0046process$0","moduleName":"ballerina.lang.query.0","fileName":"types.bal","lineNumber":93}]} path="/hospital/doctors/1/appointments?year=2023&month=07&day=01" method="GET"

We should handle this scenario


**Steps to reproduce:**

**Affected Versions:**

**OS, DB, other environment details and versions:**

**Related Issues (optional):**
<!-- Any related issues such as sub tasks, issues reported in other repositories (e.g component repositories), similar problems, etc. -->

**Suggested Labels (optional):**
<!-- Optional comma separated list of suggested labels. Non committers can’t assign labels to issues, so this will help issue creators who are not a committer to suggest possible labels-->

**Suggested Assignees (optional):**
<!--Optional comma separated list of suggested team members who should attend the issue. Non committers can’t assign issues to assignees, so this will help issue creators who are not a committer to suggest possible assignees-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

1 participant