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

add get_by_id to Organization #3712

Merged
merged 1 commit into from
Apr 29, 2019
Merged

add get_by_id to Organization #3712

merged 1 commit into from
Apr 29, 2019

Conversation

rauchy
Copy link
Contributor

@rauchy rauchy commented Apr 16, 2019

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • New Query Runner (Data Source)
  • New Alert Destination
  • Other

Description

Related Tickets & Documents

Mobile & Desktop Screenshots/Recordings (if there are UI changes)

@classmethod
def get_by_id(cls, _id):
return cls.query.filter(cls.id == _id).one()

Copy link
Member

@jezdez jezdez Apr 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we add a custom base model class that has this method (and maybe be other duplicates)?

http://flask-sqlalchemy.pocoo.org/2.3/customizing/#model-class

# in redash/models/base.py
from flask_sqlalchemy import Model

class RedashModel(Model):
    @classmethod
    def get_by_id(cls, _id):
        return cls.query.filter(cls.id == _id).one()

# ...

db = RedashSQLAlchemy(
    model_class=RedashModel,
    session_options={
        'expire_on_commit': False
    },
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea, but a bit out of scope for this PR. Let's keep it in mind for future refactors.

Copy link
Member

@jezdez jezdez Apr 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me 😀

@arikfr arikfr merged commit 21e22a2 into master Apr 29, 2019
@arikfr arikfr deleted the get-org-by-id branch April 29, 2019 18:58
harveyrendell pushed a commit to pushpay/redash that referenced this pull request Nov 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants