-
-
Notifications
You must be signed in to change notification settings - Fork 393
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
ForeignKeyField with source_field argument #55
Comments
Hi |
@godstopme Could you please provide description of database schema for your case, your models for this schema (write models the way you think they should work) and show examples of desired behaviour? |
Here's an stripped down example:
In this case, the I was going to submit a patch to fix this, but then I saw the comment that it is more complicated than I thought the fix to be. I don't see how it's complicated in the source code, so I'd like to know what I'm missing. This bug is a showstopper for me being able to use this library (and contribute to it as needed). |
A lot of the complication is taken away by #122, which now handles all PK's via a generic way, which would make this much more reliable to implement. |
Ok, I tried to have a go at this, and yes, I have a version that passes naïve tests, but it pollutes the single namespace per model. one = fields.IntField(source_field='two')
two = fields.CharField(max_length=10, source_field='one') will break. The solution would be to break Instance construction up into a from-python and a from-db, and have each of those constructors use different namespaces. |
Please, provide support for this feature. Currently ModelMeta metaclass ignores source_field for ForeignKey fields (just appends '_id' to field name). I've managed myself to fix this with one-liner directly inside tortoise-orm source code (can't create an abstract subclass of ModelMeta/Model, because
Tortoise.init
isn't setting_db
field to all internal objects of orm), but this does not seem like a reliable fix.Example where this can be helpful:
The text was updated successfully, but these errors were encountered: