@ponyorm

Страница 75 из 75
 
Alexander
26.10.2018
20:09:55
You mean, with UserAccess entity?

Luckydonald
26.10.2018
20:10:14
No, with your better version, the 2x Set



Alexander
26.10.2018
20:10:52
I think Project.get(name='foobar', owner=u) should work just fine

Google
Alexander
26.10.2018
20:11:51
Ah, you mean that the user is not owner, but just have an access

Luckydonald
26.10.2018
20:12:15
hold on

Alexander
26.10.2018
20:12:26
But in this diagram a user can have access to several projects with the same name, because only for owner the project name is unique

Luckydonald
26.10.2018
20:13:26
no, indeed owner.

I have the url /api/<owner_id:int>/<project_key>/<language>/<translation_key>, and want to check if that exists, and give an error if something doesn't. So basically check every part of the url for existence first.



Alexander
26.10.2018
20:29:44
Something like this: user = User.get(id=owner_id) if user is None: return 404 project = user.projects.select(lambda p: p.name == project_key).get() if project is None: return 404 original = project.originals.select(lambda o: o.name == language).get() if original is None: return 404 translation = original.translations.select(lambda t: t.lang == translation_key).get() if translation is None: return 404

Luckydonald
26.10.2018
20:30:26
Uh yeah, that helps!

Is that a technical limitation? I feel like having a .get(column=value) method similar to the classmethod would be quite handy

Alexander
26.10.2018
20:59:46
At this moment you need to use lambdas. In principle it is possible to add kwargs support too

Luckydonald
26.10.2018
21:04:24
I mean, I wouldn't change the select method, but there currently is no .get method there anyway, isn't it? EntityMeta: def get(entity, *args, **kwargs): if args: return entity._query_from_args_(args, kwargs, frame_depth=3).get() try: return entity._find_one_(kwargs) # can throw MultipleObjectsFoundError except ObjectNotFound: return None

Alexander
26.10.2018
21:12:20
At this moment you can't do obj.collection.select(foo=bar) or obj.collection.select().get(foo=bar) but you can do obj.collection.select().filter(foo=bar).get() or obj.collection.select(lambda item: item.foo == bar) I think there is no technical limitations which prevent implementation of the first two examples, so we can add them in the future

Google
Alexander
26.10.2018
21:13:01
Or maybe I don't fully understand the question

Luckydonald
26.10.2018
21:14:41
yeah, but I would recommend adding obj.collection.get(foo=bar) similar to Entity.get(foo=bar),

Alexander
26.10.2018
21:16:01
Ah, ok, this is a good idea

Luckydonald
27.10.2018
11:30:18


Or would I just do a = AccessUser.get(user=u, project=234) if a is None: .... ?



Alexander
27.10.2018
11:39:35
Maybe you can just define user and token as optional attributes of Access entity and remove subclasses

Luckydonald
27.10.2018
11:44:21


Or would those composite_index statements fail when using the parent class attributes?

Alexander
27.10.2018
11:48:35
Can AccessToken later be transformed to AccessUser?

Luckydonald
27.10.2018
11:49:34
Can AccessToken later be transformed to AccessUser?
No, either you get a token link, or you are a registered telegram user.

Xavier
27.10.2018
11:51:22
Hi I have a doubt, I added a column to a alredy created table via "alter table" and added this to the code and pony says that don't exist

Xavier
27.10.2018
11:54:24
i did but pony says it dont exist is the model stored in som place apart of the code?

Admin


Xavier
27.10.2018
11:54:42
postgres

Alexander
27.10.2018
11:54:57
Maybe you need to commit changes after you did alter table

Luckydonald
27.10.2018
11:56:12
The next time the script restarted, it should work

Alexander
27.10.2018
11:56:45
In PostgreSQL, alter table command can be part of transaction. Admin interface can be in auto-commit mode or in manual commit mode

Google
Xavier
27.10.2018
11:58:05
it's possible that it's a transaction problem. I will check it, thank you

Luckydonald
27.10.2018
11:58:23
Also the column name could be different to what pony expects, try setting column='...', e.g. column = Required(str, column='database_column')

Alexander
27.10.2018
12:02:53
If you want to have capital letters in a colum name, like "MyColumn_Name", you need to use double quotes around it in alter table command: alter table mytable add "MyColumn_Name" int, or else it will be created as "mycolumn_name". In general, it is easier to use lower-case names in PostgreSQL

Luckydonald
27.10.2018
12:04:19
Alexander
27.10.2018
12:08:56
> But this should have the benifit, that I can't end up with Access entities which have neither a token and a user or both of them. I think you can enforce this by adding check constraint to a table alter table access add constraint check_access_token_and_user check (token is not null and user is null or token is null and user is not null) and use just a single Access entity

Luckydonald
27.10.2018
14:04:58
Join the official Python Developers Survey 2018 and win valuable prizes: https://surveys.jetbrains.com/s3/c19-python-developers-survey-2018

Can we get PonyORM in this year, too?

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