@ponyorm

 
Страница 1 из 75
Alexey
15.09.2016
06:03:33
Welcome to Pony ORM group! Here you can discuss anything related to Pony ORM.

Mikki
15.09.2016
06:22:16
Woohoo! Hello!

Welcome :)

Андрей
19.09.2016
18:14:36
Здрасте

Google
Андрей
19.09.2016
18:14:39
Hello

Mikki
19.09.2016
18:19:46
Heya! ^^

Jannes
19.09.2016
18:22:24
Rozen
21.09.2016
14:39:32
:O

Hi :D

Mikki
21.09.2016
14:40:00
Hello, welcome!

Rozen
21.09.2016
14:40:33
thanks :D

god it took me too long to find this grup

Mikki
21.09.2016
14:43:03
Its just here -since a week or such

Rozen
21.09.2016
14:43:08
oh

Mikki
21.09.2016
14:44:57
So where did you run into?

Rozen
21.09.2016
14:46:04
ah yes

well i usually have stupid questions ?

Google
Rozen
21.09.2016
14:46:54
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
21.09.2016
14:46:57
No question is stupid ?

What's the problem you're running in to, to use that as a solution? :)

Rozen
21.09.2016
14:48:04
i just need that my "class" to have a list of strings

Alexander
21.09.2016
14:49:21
Hi everybody! @Rozzen, what database do you use?

Rozen
21.09.2016
14:50:05
sqlite3

Alexander
21.09.2016
14:55:56
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
21.09.2016
14:56:39
:O

that should be fine i guess

thanks :D

Alexander
21.09.2016
14:58:07
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
21.09.2016
14:58:51
mmm what do you mean with "compile with json1 extension"? ?

Alexander
21.09.2016
15:01:12
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
21.09.2016
15:01:31
ooh

Alexander
21.09.2016
15:02:33
It is not necessary, you can use PonyORM Json type without json1 extension.

Rozen
21.09.2016
15:02:52
i get it, but i love to learn those things

Alexey
21.09.2016
15:10:49
https://docs.ponyorm.com/json.html

Alexander
21.09.2016
15:35:53
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/

Google
Alexey
21.09.2016
15:36:24
if you don't care about performance at this point, you don't need the JSON1 extension

Rozen
21.09.2016
15:36:47
if you don't care about performance at this point, you don't need the JSON1 extension
yes yes i got it, but i'd like to understand how to get more optimization in the future

Alexander
21.09.2016
15:37:14
I think it would be more convenient if future versions of SQLite include json1 by default

Alexey
21.09.2016
15:37:15
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

Rozen
21.09.2016
15:38:38
but at least i know what to read when that happens

stupid question number two!

to set an image as a property?

Alexey
21.09.2016
16:04:04
usually it is a str - because you probably will keep an image url in this property

Alexander
21.09.2016
16:12:53
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
23.09.2016
16:10:04
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

Alexander
23.09.2016
16:28:55
I think it should work. Maybe the error is caused by some other reason. Can you provide a traceback with the error message?

Google
Rozen
23.09.2016
16:46:31
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

Admin


Rozen
23.09.2016
23:19:07
<class 'pony.orm.sqltranslation.IncomparableTypesError'> ("Incomparable types 'Animal' and 'Set of Dog' in expression: h.pet == dog",)

aah

because i have like

class Dog(Animal): humans = Set("Human")

h in dog.humans

h in dog.humans
should be this way?

ok i changed to that and now i get

<class 'TypeError'> ("Expression dog.humans has unsupported type 'Set'",)

Alexander
23.09.2016
23:27:15
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

Rozen
23.09.2016
23:28:58
i have a one to one relationship with some id that isn't the primary key

dog= Dog.get(oexr_id = id)

Alexander
23.09.2016
23:29:53
Can you paste the definitions of Animal, Dog and Human classes?

Rozen
23.09.2016
23:32:30
yep gimme a sec

pastebin or right here?

Google
Alexander
23.09.2016
23:39:48
any way

Rozen
23.09.2016
23:40:36
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
23.09.2016
23:41:56
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

class Animal(db.Entity): ... owner = Required(Human) class Human(db.Entity): ... 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

Rozen
23.09.2016
23:47:13
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

Alexander
23.09.2016
23:56:42
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.

Rozen
23.09.2016
23:57:23
hmmm ok

i get

Dog[3]

Alexander
24.09.2016
00:16:05
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

 
Страница 1 из 75