Dynamic Relationship

16 views
Skip to first unread message

Elias Coutinho

unread,
Sep 16, 2022, 9:02:55 PM9/16/22
to peewee-orm
Good evening everyone.
How wonderful I found this group!
I am a big fan of peewee.

My question is very specific and I think I will find the answer I want here:

I use a software here where it creates tables dynamically.
First it creates a table with the company data.
After creating it it uses the row ID to create the tables that will relate to this record. That's why I have trouble making the relationships in the queries.
I will try to represent it here below:

There is a table called Companies.
1 - Company with name X
2 - Company with name Y
3 - Company with name Z

Each time he creates a row in the Companies table he raw a table consisting of the id and other information as below:

Table Funcionarios1 (fields identical to the others)
Table Funcionarios2 (identical fields to the others)
Table Funcionarios3 (identical fields to the others)

Horrible, but I think this is done on purpose to make it more difficult.

My problem is to join the records of the Company table with the records of the tables Employees 1, 2, 3, n that he created.

How could I do this? Just so you know that this bank in this way was not my creation.

Translated with www.DeepL.com/Translator (free version)

Charles Leifer

unread,
Sep 17, 2022, 11:32:19 AM9/17/22
to peewe...@googlegroups.com
Unfortunately, I'm not sure how to advise you on this. You can always
dynamically create a model-class for a particular table, e.g.

https://github.com/coleifer/peewee/blob/master/playhouse/reflection.py#L725-L778

Specifically, this builds up a dict of attrs corresponding to the
fields, then creating a new model using type('employees1',
(BaseModel,), attrs).

Alternatively you can always just create a `Table` dynamically, e.g.

c = Company.get(Company.name == 'Z')
c_id = c.id # Get the company ID.
F = Table('Funcionarios%d' % c_id)

query = (Company
.select(Company, F.c.name, F.c.another_column, F.c.third_column, ...)
.join_from(Company, F, on=(Company.id == F.c.company_id)))

Hope these ideas provide some help.
> --
> You received this message because you are subscribed to the Google Groups "peewee-orm" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to peewee-orm+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/peewee-orm/e0c10ef7-df53-4a77-815e-c76fa87c772an%40googlegroups.com.

Rizwan Ali m.sarwar

unread,
Sep 19, 2022, 6:01:08 AM9/19/22
to peewe...@googlegroups.com
Hi There!
We have a team of seasoned experts who acquire hand-picked links for you manually. We help you to connect with real blogs and establish real business connections. Do we have much experience in SEO (Search Engine Optimization) especially Guest Blogging (Guest Posting, Blog Posting Outreach Paid Guest Posting • link insertion (in the existing articles) • Home page link • (banner, ads, videos) what can you like, please specify for a • per month • term or • 4 months • 6 months • or per year? HQ Blog Contribution), and writing of blog content, website materials. We have been working with so many clients who are satisfied with our services and we also provide a refund policy on non-satisfaction of clients. It is the main reason to build trust with clients.

Please tell us about your requirements, We will send you websites according to your requirements.
Let me know what you think about it?

Thanks & waiting for your reply.

Mailtrack Sender notified by
Mailtrack
09/19/22, 03:00:52 PM
Reply all
Reply to author
Forward
0 new messages