Giter Site home page Giter Site logo

Comments (4)

baumatron avatar baumatron commented on August 10, 2024 2

Thanks for your reply and feedback! I unfortunately am also pretty busy at the moment so I won't be able to look at this either for the time being.

For anyone who might be trying to a create many-to-many association table and need to save it with achemy dumps, I came up with a workaround for that specific case. I created a mapped class that would create a table with the same shape that I needed. That way alchemy dumps will pick it up since it will be enumerated as a subclass of db.Model.

For example:

user_to_project_table = db.Table(
    'user_to_project',
    Base.metadata,
    db.Column('user_id', db.ForeignKey('user.id'), primary_key=True),
    db.Column('project_id', db.ForeignKey('project.id'), primary_key=True)
)

Becomes something like:

class UserToProjectTable(db.Model):
    __tablename__ = 'user_to_project'
    user_id = db.Column('user_id', db.ForeignKey('user.id'), primary_key=True)
    project_id = db.Column('project_id', db.ForeignKey('project.id'), primary_key=True)

Then in your classes where you declare the relationship, the relationship's 'secondary' property can be assigned the string 'user_to_project' instead of user_to_project_table.

from alchemydumps.

cuducos avatar cuducos commented on August 10, 2024

This seems to be because the base declarative class's subclasses are the only things enumerated when creating dumps, which will result in missing other data.

That's completely true, @baumatron. You've found a huge bug.

Unfortunately, I cannot take a look on these issues this soon because things are kind of hectic here the following weeks.

However, feel free to send e PR if you want to give it a try.

Usually I follow a TDD (test-driven development) approach:

  1. Add the missing models at tests/app.py (e.g. many-to-many relationships this time)
  2. Write tests for the new models at tests/test_commands.py
  3. Fix the package ; )
  4. Add the novelties to theREADME.md

from alchemydumps.

cuducos avatar cuducos commented on August 10, 2024

Many thanks again @baumatron!
I edited your last comment just to add Python color to the code bits, ok?

from alchemydumps.

baumatron avatar baumatron commented on August 10, 2024

Perfect, thanks for making that more readable.

from alchemydumps.

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.