Skip to content

Virtual Fields combined with Alias not working #735

@unle70

Description

@unle70

Hello,

I tried to set-up a Virtual field (first time for me). In my case, it's the "full_name" field in web2py auth_user, defined as:
Field.Virtual('full_name', lambda row: f'{row.auth_user.last_name} {row.auth_user.first_name}')

I see it's working well when trying to access the table in a simple way. When I do a "select" for all fields, I get this one as well.

db(db.some_table).select(
    db.some_table.ALL,
    db.auth_user..ALL
    left=db.some_table.on(db.auth_user.id == db.some_table.user1)
)

But if I try to refer to this table with alias (as below), I cannot see this virtual field anymore.

db(db.some_table).select(
    db.some_table.ALL,
    db.auth_user.with_alias('alias1').ALL
    left=db.some_table.on(db.auth_user.with_alias('alias1').id == db.some_table.user1)
)

I'm guessing the problem comes from stating the explicit table name ("auth_user") in the lambda function, which doesn't work when that table has an alias. Is there a way around this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions