Code Monkey home page Code Monkey logo

Comments (3)

GittCatt avatar GittCatt commented on July 28, 2024

Are you sure you've posted a correct example? The following works for me:

from pony.orm import *

db = Database()

class MyEntity(db.Entity):
    a = Required(str)
    b = Required(str)
    PrimaryKey(a, b)

db.bind(provider='sqlite', filename=':memory:')
db.generate_mapping(create_tables=True)

ent = MyEntity(a='Key1', b='Key2')
commit()

primary_key = ent.get_pk()
>>> MyEntity[primary_key]
MyEntity['Key1','Key2']

from pony-doc.

paxet avatar paxet commented on July 28, 2024

My fault, sorry.
The tuple returned from get_pk() was getting converted to str to be stored in another table, a simple 'eval' solved it.

from pony.orm import *

db = Database()

class MyEntity(db.Entity):
    a = Required(str)
    b = Required(str)
    PrimaryKey(a, b)

db.bind(provider='sqlite', filename=':memory:')
db.generate_mapping(create_tables=True)

with db_session():
    ent = MyEntity(a='Key1', b='Key2')
    primary_key = str(ent.get_pk())
    ent = MyEntity[eval(primary_key)]
>>> MyEntity[eval(primary_key)]
MyEntity['Key1', 'Key2']

from pony-doc.

sashaaero avatar sashaaero commented on July 28, 2024

First of all I think this issue relates to pony itself, not pony-doc repository.
About composite keys - it was bug in Pony that we've fixed here. And will be released soon in Pony 0.7.7

from pony-doc.

Related Issues (2)

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.