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

Default model pk: id = fields.IntField(pk=True) #34

Merged
merged 3 commits into from Jul 26, 2018

Conversation

grigi
Copy link
Member

@grigi grigi commented Jul 23, 2018

If a pk isn't defined, we create a pk called id for that model.
Also added Model method tests.

Based on #28 (which is based on #33). So please only merge this after those.

@grigi grigi mentioned this pull request Jul 23, 2018
72 tasks
@coveralls
Copy link

coveralls commented Jul 23, 2018

Pull Request Test Coverage Report for Build 88

  • 7 of 7 (100.0%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.7%) to 90.413%

Files with Coverage Reduction New Missed Lines %
tortoise/models.py 1 89.1%
Totals Coverage Status
Change from base Build 84: 0.7%
Covered Lines: 1767
Relevant Lines: 1904

💛 - Coveralls

@coveralls
Copy link

Pull Request Test Coverage Report for Build 77

  • 102 of 102 (100.0%) changed or added relevant lines in 10 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+1.6%) to 90.44%

Files with Coverage Reduction New Missed Lines %
tortoise/models.py 1 89.1%
Totals Coverage Status
Change from base Build 60: 1.6%
Covered Lines: 1774
Relevant Lines: 1911

💛 - Coveralls

@grigi
Copy link
Member Author

grigi commented Jul 23, 2018

@Zeliboba5 Please review (commit e472e10 only)
Based on #28 (which is based on #33). So please only merge this after those.

We need a better way of doing this. Any suggestions?

If a pk isn't defined, we create a pk called id for that model.
Also added Model method tests.
@grigi
Copy link
Member Author

grigi commented Jul 25, 2018

@Zeliboba5 I rebased it on #29 now that there is nothing standing in the way anymore. This PR should be clean now.

docs/models.rst Outdated
This code defines integer primary key for table. Sadly, currently only simple integer pk is supported.
This code defines integer primary key for table.
If you don't define a primary key, we will create a Integer primary key with name of ``id`` for you.
Sadly, currently only simple integer primary key is supported.
Copy link
Member

Choose a reason for hiding this comment

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

May be should force using 'id field at the moment? Current inner implementations using id all over the place and setting another name for pk will fall everything apart.
It made me realise why django needed separate pk field that stores reference to pk field

Copy link
Member Author

Choose a reason for hiding this comment

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

I was having similar thoughts when I did this.
The reason I forced a default id fields was because of all the internal code using .id everywhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

Or should we copy Django, and have a pk field, and whatever has pk=True is just an alias to pk?
Or should we just stick to id?

Copy link
Member

Choose a reason for hiding this comment

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

Then we should fix this description for now, because it's confusing and gives hope that you can use different name for pk. I created issue regarding this #36 and hope we will fix it before 1.0 because it's quite important in my opinion.
Could you also add some kind of validation that none other fields were defined with pk=True while we are forcing it ourselves

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I'll do that tonight.

@grigi
Copy link
Member Author

grigi commented Jul 25, 2018

@Zeliboba5 I updated the docs as you requested.
I also noticed that there was a few more doc changes that needed to be done. So, I did them as well.

@abondar
Copy link
Member

abondar commented Jul 26, 2018

👍

@abondar abondar merged commit bae782c into tortoise:feature/init-refactoring Jul 26, 2018
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.

None yet

3 participants