question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deserialize Association Objects

See original GitHub issue

Hi,

I’ve created an Association Table as described in the SQLAlchemy manual, however when I try to load on a POST request I get this response:

RuntimeError: Model <class 'app.products.models.SoldProducts'> has multiple primary keys

Which is true, as the association table creates a compound key. How should I proceed?

Thanks!

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
maithamcommented, Oct 5, 2019

Would it be possible to provide a example for such models?

class Skill(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), unique=True, nullable=False)
    users = db.relationship("Proficiency", back_populates="skill", lazy=True)

    def __repr__(self):
        return "<Skill %r>" % self.name

class Proficiency(db.Model):
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True)
    skill_id = db.Column(db.Integer, db.ForeignKey("skill.id"), primary_key=True)
    score = db.Column(db.Integer(), nullable=False)

    skill = db.relationship("Skill", back_populates="users")
    user = db.relationship("User", back_populates="skills")

    def __repr__(self):
        return "<Proficiency %r>" % self.score

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), unique=True, nullable=False)
    skills = db.relationship("Proficiency", back_populates="user", cascade="all,delete")

    def __repr__(self):
        return "<User %r>" % self.name
1reaction
antgelcommented, Sep 8, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolve JPA association while deserializing JAX-RS JSON ...
What we are doing is deserializing the JSON payload into dedicated DTO objects. In the sample case this would mean to have a...
Read more >
Serialize/Deserialize objects by reference to transfer json ...
I'm trying here to address few of them: Serialize/Deserialize object by reference or preserve association between objects; Serialize/Deserialize ...
Read more >
Introducing serializr: serializing and deserializing object ...
Serializing object graphs to JSON and especially deserializing object graphs from JSON is often a cumbersome task in JavaScript.
Read more >
Jackson - Bidirectional Relationships - Baeldung
Then we'll see how to serialize entities with bidirectional relationships. Finally, we'll deserialize them. 2. Infinite Recursion.
Read more >
Ember Data: A Tutorial and Examples of the Ember.js ... - Toptal
Ember Data employs RESTSerializer for creating objects from API responses (deserialization) and for generating JSON for API requests (serialization).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found