Skip to content

Is it possible to "override" the default FROM of a Model query? #2628

@Vectarian-Jorge

Description

@Vectarian-Jorge

When you have a Model MyModel any query executed with MyModel.query()... includes a FROM clause to MyModel.tableName (public.my_model, for example) by default. Is it possible to change/override that FROM for specific queries?

Is it possible to execute MyModel.query().fromRaw('public.my_custom_model(?)', foo)... somehow?
I know I could create another model for this but public.my_custom_model(?) has the same structure as public.my_model so everything I've implemented in MyModel (virtual columns, modifiers, hooks...) and every class extending MyModel will be valid for this new model too.

It would be more of a hassle to maintain everything if I need to have a new class just for 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