Open wallneradam opened 4 years ago
Hmm, option 1 is backwards compatible, and option 2, whilst clean (specify if you want it, else don't bother) could break existing code. Which will let me rather err towards option 1.
Yes, specifying if a field was explicitly requested or just automatically would be useful. Auto fields often are backwards fk/o2o/m2m and primary key.
Are you saying a property annotated: bool
? False if entierly auto-generated, and True otherwise?
Yes specifying auto fields would be great as well.
I mean true if you have the annotation for backward relation in the model like:
parameters: ReverseRelation['UserParameter']
I'll see about adding some of this to #206 I'll set the backward relation annotated to True if you explicitly named the backwards relation. Right now we ignore the declared reverse relations, as they are only for enabling type hinting at this stage.
No, #206 is big enough, I'm going to merge it and do a new PR. So many things needing my attention at this time, I'll have to draw up a priority list.
Is it OK to assume that an explicitly defined field (e.g. IntField) is a properly annotated field?
Then annotated can only be False
for reverse relations (FK/O2O/M2M)?
Oh, and what do we do for an autogenerated id
PK field?
You'd want to know if that is auto or not?
So is annotated
possibly the wrong thing? are you looking for explicitly defined
?
Or maybe both?
As in a auto_definition
which would only be true if field has been automatically defined (or explicit?), and annotated it it has been manually annotated?
Or should we report the manual annotation?
e.g:
explicit
→ If it has been explicitly setup via either a field or as a related_field
annotation
→ Manual type annotation.
Or am I missing the point here?
Released v0.15.6 with ability to disable the reverse relation for FK/O2O. (so half the work on this issue)
Wouldn't it be more "pythonic" to use related_name=None instead of related_name=False? Just a thought.
Is your feature request related to a problem? Please describe. I think a lot of times you just don't need the backward relation, which is now automatically created by Tortoise. It can be a problem, when you have multiple interpretation for the same model. E.g. a user can be referenced multiple times, but never want to use it backwards.
Describe the solution you'd like I have 2 solution proposals. Either or both would be good.
related_name
parameter asFalse
or empty string (I prefer False):Additional context I have this problem in my PR #260 . If you don't agree with this request, I still need to know somehow from
backward_*_fields
, which field has annotation at the other end. It could be described in a new property called e.g.annotated
.