 Alexey
    Alexey 
    
    
        
        
        
        Welcome to Pony ORM group!
        Here you can discuss anything related to Pony ORM.
    
 
     Mikki
    Mikki 
    
    
        
        
        
        Woohoo! Hello!
    
 
     Mikki
    Mikki 
    
    
        
        
        
        Welcome :)
    
 
     Anonymous
    Anonymous 
    
    
        
        
        
        Здрасте
    
 
     Anonymous
    Anonymous 
    
    
        
        
        
        Hello
    
 
     Mikki
    Mikki 
    
    
        
        
        
        Heya! ^^
    
 
     Jannes
    Jannes 
    
    
 
     Rozen
    Rozen 
    
    
        
        
        
        :O
    
 
     Rozen
    Rozen 
    
    
        
        
        
        Hi :D
    
 
     Mikki
    Mikki 
    
    
        
        
        
        Hello, welcome!
    
 
     Rozen
    Rozen 
    
    
        
        
        
        thanks :D
    
 
     Rozen
    Rozen 
    
    
        
        
        
        god it took me too long to find this grup
    
 
     Mikki
    Mikki 
    
    
        
        
        
        Its just here -since a week or such
    
 
     Rozen
    Rozen 
    
    
        
        
        
        oh
    
 
     Mikki
    Mikki 
    
    
        
        
        
        So where did you run into?
    
 
     Rozen
    Rozen 
    
    
        
        
        
        ah yes
    
 
     Rozen
    Rozen 
    
    
        
        
        
        well i usually have stupid questions 😆
    
 
     Rozen
    Rozen 
    
    
        
        
        
        now, what i'm looking for is to know if it has any sense to have a property in my class that is a Set(str)
    
 
     Mikki
    Mikki 
    
    
        
        
        
        No question is stupid 😁
    
 
     Mikki
    Mikki 
    
    
        
        
        
        What's the problem you're running in to, to use that as a solution? :)
    
 
     Rozen
    Rozen 
    
    
        
        
        
        i just need that my "class" to have a list of strings
    
 
     Alexander
    Alexander 
    
    
        
        
        
        Hi everybody!
        @Rozzen, what database do you use?
    
 
     Rozen
    Rozen 
    
    
        
        
        
        sqlite3
    
 
     Alexander
    Alexander 
    
    
        
        
        
        Right now Set attributes can be used only with entity types, but in the distant future we can add support of Set(str) as well. At this moment you can store array of strings inside Json attribute:
        class MyEntity(dn.Entity):
            name = Required(str)
            tags = Optional(Json)
        ...
        x = MyEntity(name='foo')
        x.tags = ['one', 'two', 'three']
    
 
     Rozen
    Rozen 
    
    
        
        
        
        :O
    
 
     Rozen
    Rozen 
    
    
        
        
        
        that should be fine i guess
    
 
     Rozen
    Rozen 
    
    
        
        
        
        thanks :D
    
 
     Alexander
    Alexander 
    
    
        
        
        
        We support Json attribute in all databases (SQLite, MySQL, PostgreSQL, Oracle). To get best performance with SQLite you should compile it with json1 extension, but Json will work without that extension too, just a bit slower.
    
 
     Rozen
    Rozen 
    
    
        
        
        
        mmm what do you mean with "compile with json1 extension"? 😆
    
 
     Alexander
    Alexander 
    
    
        
        
        
        As I understand it, SQLite does not include Json1 extension by default, and you need somehow enable it:
        https://www.sqlite.org/json1.html
        https://www.sqlite.org/loadext.html
    
 
     Rozen
    Rozen 
    
    
        
        
        
        ooh
    
 
     Alexander
    Alexander 
    
    
        
        
        
        It is not necessary, you can use PonyORM Json type without json1 extension.
    
 
     Rozen
    Rozen 
    
    
        
        
        
        i get it, but i love to learn those things
    
 
     Alexey
    Alexey 
    
    
        
        
        
        https://docs.ponyorm.com/json.html
    
 
     Rozen
    Rozen 
    
    
 
     Rozen
    Rozen 
    
    
        
        
        
        it's mandatory to use C?
    
 
     Alexander
    Alexander 
    
    
        
        
        
        As I understand, yes. Actually, I have no experience with compiling that stuff myself. Maybe someone can explain better. There is an blog post of Charles Leifer in which he describes how to build SQLite with json1: http://charlesleifer.com/blog/using-the-sqlite-json1-and-fts5-extensions-with-python/
    
 
     Alexey
    Alexey 
    
    
        
        
        
        if you don't care about performance at this point, you don't need the JSON1 extension
    
 
     Rozen
    Rozen 
    
    
 
     Alexander
    Alexander 
    
    
        
        
        
        I think it would be more convenient if future versions of SQLite include json1 by default
    
 
     Alexey
    Alexey 
    
    
        
        
        
        check out this article http://charlesleifer.com/blog/using-the-sqlite-json1-and-fts5-extensions-with-python/
    
 
     Alexey
    Alexey 
    
    
        
        
        
        so currently you can just use SQLite as is
        and once you'll see that you need better perfomance with JSON, you can think about compiling it with JSON1 module
    
 
     Rozen
    Rozen 
    
    
 
     Rozen
    Rozen 
    
    
        
        
        
        but at least i know what to read when that happens
    
 
     Rozen
    Rozen 
    
    
        
        
        
        stupid question number two!
    
 
     Rozen
    Rozen 
    
    
        
        
        
        to set an image as a property?
    
 
     Alexey
    Alexey 
    
    
        
        
        
        usually it is a str - because you probably will keep an image url in this property
    
 
     Alexander
    Alexander 
    
    
        
        
        
        You can also store an image as a BLOB data inside the database (use buffer type for that), but usually it is much better to save images outside of the database and store the filename in a textual column.
    
 
     Rozen
    Rozen 
    
    
        
        
        
        silly question number 35! (?)
    
 
     Rozen
    Rozen 
    
    
        
        
        
        let's say i have a class Human(db.Entity):
        that has the propery pet = Required(Animal)
    
 
     Rozen
    Rozen 
    
    
        
        
        
        and i have the class Dog(Animal)
    
 
     Rozen
    Rozen 
    
    
        
        
        
        and i have a variable is a dog
    
 
     Rozen
    Rozen 
    
    
        
        
        
        so... i want to do something like a select(h for h in Human if h.pet == dog)
    
 
     Rozen
    Rozen 
    
    
        
        
        
        but dog isn't an animal, it's a dog, a child class of animal
    
 
     Rozen
    Rozen 
    
    
        
        
        
        and python implotes when i try to do that
    
 
     Rozen
    Rozen 
    
    
        
        
        
        sorry my english isn't tha best
    
 
     Alexander
    Alexander 
    
    
        
        
        
        I think it should work. Maybe the error is caused by some other reason. Can you provide a traceback with the error message?
    
 
     Rozen
    Rozen 
    
    
        
        
        
        grr i just fixed using ids
    
 
     Rozen
    Rozen 
    
    
        
        
        
        when i have time again i'll try and if it fails
    
 
     Rozen
    Rozen 
    
    
        
        
        
        i'll send the error message
    
 
     Rozen
    Rozen 
    
    
        
        
        
        now i got the error
    
 
     Rozen
    Rozen 
    
    
        
        
        
        <class 'pony.orm.sqltranslation.IncomparableTypesError'>
        ("Incomparable types 'Animal' and 'Set of Dog' in expression: h.pet == dog",)
    
 
     Rozen
    Rozen 
    
    
        
        
        
        aah
    
 
     Rozen
    Rozen 
    
    
        
        
        
        because i have like
    
 
     Rozen
    Rozen 
    
    
        
        
        
        class Dog(Animal):
          humans = Set("Human")
    
 
     Rozen
    Rozen 
    
    
        
        
        
        h in dog.humans
    
 
     Rozen
    Rozen 
    
    
        
        
        
        ok i changed to that and now i get
    
 
     Rozen
    Rozen 
    
    
        
        
        
        <class 'TypeError'>
        ("Expression dog.humans has unsupported type 'Set'",)
    
 
     Alexander
    Alexander 
    
    
        
        
        
        Can you show how you got the value of the dog variable
    
 
     Alexander
    Alexander 
    
    
        
        
        
        It seems that it is not a dog, but a set of dogs
    
 
     Rozen
    Rozen 
    
    
        
        
        
        i have a one to one relationship with some id that isn't the primary key
    
 
     Rozen
    Rozen 
    
    
        
        
        
        dog= Dog.get(oexr_id = id)
    
 
     Alexander
    Alexander 
    
    
        
        
        
        Can you paste the definitions of Animal, Dog and Human classes?
    
 
     Rozen
    Rozen 
    
    
        
        
        
        yep gimme a sec
    
 
     Rozen
    Rozen 
    
    
        
        
        
        pastebin or right here?
    
 
     Alexander
    Alexander 
    
    
        
        
        
        any way
    
 
     Rozen
    Rozen 
    
    
        
        
        
        class Animal(db.Entity):
            id_animal       =PrimaryKey(int,size=64,auto=True)
            humans          =Set("Human")
            classtype = Discriminator(str)
            _discriminator_="Animal"
            oexr       =Required(OnlyExr)
        class Human(db.Entity):
            user        =Required(User)
            pet        =Required(Animal)
            classtype = Discriminator(str)
            _discriminator_="Human"
        class OnlyExr(db.Entity):
            id_exr    =PrimaryKey(int,size=64)
            animals   =Set("Animal")
            name      =Required(str)
        class Dog(Animal):
            race    =Optional(String)
            _discriminator_="Dog"
    
 
     Alexander
    Alexander 
    
    
        
        
        
        It looks strange that in your schema a human can has only one (required!) pet, while a pet belongs to many humans. I think it should be the other way
    
 
     Alexander
    Alexander 
    
    
        
        
        
        class Animal(db.Entity):
            ...
            owner = Required(Human)
        
        class Human(db.Entity):
            ...
            pets = Set(Animal)