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

Base Models overriding table name #380

Closed
josephmancuso opened this issue Feb 10, 2021 · 5 comments
Closed

Base Models overriding table name #380

josephmancuso opened this issue Feb 10, 2021 · 5 comments
Labels
bug An existing feature is not working as intended needs more info This is a ticket that requires more information from the author

Comments

@josephmancuso
Copy link
Member

Describe the bug
If you have a base model it is overriding the table name of the child model.

To Reproduce
Steps to reproduce the behavior:

  1. create a BaseModel class.
  2. Inherit it onto your User model
  3. Make a query call. It will use base_models table instead of users table
@josephmancuso josephmancuso added the bug An existing feature is not working as intended label Feb 10, 2021
@josephmancuso
Copy link
Member Author

Cannot replicate this

@josephmancuso
Copy link
Member Author

josephmancuso commented Feb 10, 2021

class BaseModel(Model):
    pass

class Store(BaseModel):

    __connection__ = "dev"

    __fillable__ = ["name"]

    __guarded__ = ["bob"]

    @scope
    def by_search(self, query, search, search_key='title'):
        if not search:
            return query
        search_queries = search.split()
        for search_query in search_queries:
            if ':' in search_query:
                key, value = search_query.split(':')
                if value in ('true', 'false'):
                    query = query.where(key, 1 if value == 'true' else 0)
                else:
                    query = query.where(key, 'like', f"%{value}%")
            else:
                query = query.where(search_key, 'like', f"%{search_query}%")
        return query

print(Store.where("name", "Walmart").to_sql()) #== SELECT * FROM "stores" WHERE "stores"."name" = 'Walmart'

@josephmancuso
Copy link
Member Author

@resmo

@josephmancuso
Copy link
Member Author

maybe you imported the basemodel accidentally? can I see maybe where you imported this user model you were talking about?

@josephmancuso josephmancuso added the needs more info This is a ticket that requires more information from the author label Feb 10, 2021
@josephmancuso
Copy link
Member Author

Will close this issue until more context is given

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An existing feature is not working as intended needs more info This is a ticket that requires more information from the author
Projects
None yet
Development

No branches or pull requests

1 participant