Giter Club home page Giter Club logo

Comments (5)

abondar avatar abondar commented on May 13, 2024

Hi
Disregarding source_field is actually not desired behaviour and I think I will try to fix it soon, but fixing it is a little more complex than I would like it to be, cause some parts of code at the moment relies on the fact that {}_id field presence is guaranteed for every FK field.

from tortoise-orm.

abondar avatar abondar commented on May 13, 2024

@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?

from tortoise-orm.

rockstar avatar rockstar commented on May 13, 2024

Here's an stripped down example:

class Task(models.Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=10)

class Server(models.Model):
    id = fields.IntField(pk=True)
    label = fields.CharField(max_length=64)

class ExecutionEntry(models.Model):

    class Meta:
        unique_together = ('task', 'server')

    executed_at = fields.DatetimeField()
    task = fields.ForeignKey('models.Task', related_name='history', source_field='task')
    server = fields.ForeignKey('models.Server', related_name='history', source_field='server')

In this case, the execution_entry table is a join table with some extra metadata, and rather that task_id and server_id as the fields, they are task and server (because existing database).

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).

from tortoise-orm.

grigi avatar grigi commented on May 13, 2024

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.
If you want to go ahead and implement this, please do :-)
Please base it on the #122 branch, and then rebase with master once that is merged (It appears fully functional, just missing out on some tests).

from tortoise-orm.

grigi avatar grigi commented on May 13, 2024

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.
so, e.g.

    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.

from tortoise-orm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.