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

dynamic_order_by does not append table name after order by #1354

Open
sujessie opened this issue Nov 7, 2024 · 0 comments
Open

dynamic_order_by does not append table name after order by #1354

sujessie opened this issue Nov 7, 2024 · 0 comments

Comments

@sujessie
Copy link

sujessie commented Nov 7, 2024

This problem only happens if two tables have the same column name and a join is performed.
 
Example:

struct User
{
    uint32_t Id;
    std::string Name;
    ...
};

struct OtherUser
{
    uint32_t Id;
    std::string Name;
    std::string LastName;
    ...
};

constexpr auto userStruct = sqlite_orm::struct_<UserStruct>(&User::Id, &User::Name, &OtherUser::LastName);

auto orderBySql = sqlite_orm::dynamic_order_by(storage);

switch (orderBy)
{
case Name:
    orderBySql.push_back(sqlite_orm::order_by(&User::Name).asc())
case LastName:
    orderBySql.push_back(sqlite_orm::order_by(&User::LastName).asc())
}

auto users = storage.select(
    userStruct,
    sqlite_orm::left_join<OtherUser>(
        sqlite_orm::on(sqlite_orm::c(&User::Id) == &OtherUser::Id)
    ),
    orderBySql,
    sqlite_orm::limit(limitCount.value_or(-1))
);

If order by is Name, the generated query results in the error:
Error while executing SQL query on database 'mydatabase': ambiguous column name: Name

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

2 participants