Welcome to Pony ORM group!
Here you can discuss anything related to Pony ORM.
god it took me too long to find this grup
Its just here -since a week or such
So where did you run into?
well i usually have stupid questions ?
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)
No question is stupid ?
What's the problem you're running in to, to use that as a solution? :)
i just need that my "class" to have a list of strings
@Rozzen, what database do you use?
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:
name = Required(str)
tags = Optional(Json)
x = MyEntity(name='foo')
x.tags = ['one', 'two', 'three']
that should be fine i guess
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.
mmm what do you mean with "compile with json1 extension"? ?
As I understand it, SQLite does not include Json1 extension by default, and you need somehow enable it:
It is not necessary, you can use PonyORM Json type without json1 extension.
i get it, but i love to learn those things
it's mandatory to use C?
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/
if you don't care about performance at this point, you don't need the JSON1 extension
I think it would be more convenient if future versions of SQLite include json1 by default
check out this article http://charlesleifer.com/blog/using-the-sqlite-json1-and-fts5-extensions-with-python/
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
but at least i know what to read when that happens
stupid question number two!
to set an image as a property?
usually it is a str - because you probably will keep an image url in this property
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.
silly question number 35! (?)
let's say i have a class Human(db.Entity):
that has the propery pet = Required(Animal)
and i have the class Dog(Animal)
and i have a variable is a dog
so... i want to do something like a select(h for h in Human if h.pet == dog)
but dog isn't an animal, it's a dog, a child class of animal
and python implotes when i try to do that
sorry my english isn't tha best
I think it should work. Maybe the error is caused by some other reason. Can you provide a traceback with the error message?
grr i just fixed using ids
when i have time again i'll try and if it fails
i'll send the error message
now i got the error
("Incomparable types 'Animal' and 'Set of Dog' in expression: h.pet == dog",)
because i have like
humans = Set("Human")
h in dog.humans
ok i changed to that and now i get
("Expression dog.humans has unsupported type 'Set'",)
Can you show how you got the value of the dog variable
It seems that it is not a dog, but a set of dogs
i have a one to one relationship with some id that isn't the primary key
dog= Dog.get(oexr_id = id)
Can you paste the definitions of Animal, Dog and Human classes?
yep gimme a sec
pastebin or right here?
classtype = Discriminator(str)
classtype = Discriminator(str)
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
owner = Required(Human)
pets = Set(Animal)
And than you can find a dog by primary key:
dog = Dog[dog_id]
And find an owner of this dog:
owner = dog.owner
Yeah i know xD
But i have like. Its a town with dogs that "have" many homes
And i want to get every person that have that dog as a pet
Like, those dogs choose where to eat, spend the time and sleep
Then probably the relation should be many-to-many (two Set attributes). But anyway, if any human of this city is required to have a dog, then select(h for h in Human if h.pet == dog) looks correct. But the error says that the value of a dog variable is not a single dog, but a set of dogs. You can print the variable and see its value.
Then it is strange that the error says that you are comparing Animal with a Set of Dog. I don't see any Set here