You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've 3 tables: "tasks", "services" and "assoc_tasks_services".
They contain data like this:
tasks:
task_id
user_id
price
...
...
...
84
1
174.25
85
1
250.25
86
1
300.00
87
1
1050.49
88
1
600.00
services:
service_id
name
...
...
4
Service_1
5
Service_2
19
Service_3
assoc_tasks_services:
task_id
service_id
count
...
...
...
84
4
0
85
5
0
86
19
3
87
19
6
88
19
1
88
4
0
So, in "tasks" I keep tasks, which may include several services, in "services" I keep names of services, their prices, etc., and in "assoc_tasks_services" I keep associations: which task, which services and count of service (for each service it might be 0, 1, or more).
There are 2 problems:
1.) I can't use .limit() correctly. For example, I need only last 5 tasks (84-88), but when I make query, it returns 85, 86, 87, 88 and 88 (it doesn't count 2 entries of task №88 as one).
2.) How can I attach property "count" of table "assoc_tasks_services" in every service in every task?
Please, help me. I'm not good at programming, but I'm trying to understand how can I realize it. Thank you!
tasks = await get_users_tasks(1)
for task in tasks:
for service in task.services:
print(f'Task №{task.task_id} - {service.name}. Count: {task.count}')
It returns:
Task №88 - Service_3. Count: {0, 1} # But I need Count: {1}, not {0, 1}, because count of Service_3 is 1 for Task №88 according to the table
Task №88 - Service_1. Count: {0, 1} # But I need Count: {0}, not {0, 1}, because count of Service_1 is 0 for Task №88 according to the table
Task №87 - Service_3. Count: {6} # Correct
Task №86 - Service_3. Count: {3} # Correct
Task №85 - Service_2. Count: {0} # Correct
tasks = await get_users_tasks(1)
for task in tasks:
for service in task.services:
print(f'Task №{task.task_id} - {service.name}. Count: {service.count}')
It returns:
Task №88 - Service_3. Count: {1, 3, 6} # But I need Count: {1}, not {1, 3, 6}, because count of Service_3 is 1 for Task №88 according to the table
Task №88 - Service_1. Count: {0} # Correct
Task №87 - Service_3. Count: {1, 3, 6} # Incorrect
Task №86 - Service_3. Count: {1, 3, 6} # Incorrect
Task №85 - Service_2. Count: {0} # Correct
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Greetings,
I've 3 tables: "tasks", "services" and "assoc_tasks_services".
They contain data like this:
tasks:
services:
assoc_tasks_services:
So, in "tasks" I keep tasks, which may include several services, in "services" I keep names of services, their prices, etc., and in "assoc_tasks_services" I keep associations: which task, which services and count of service (for each service it might be 0, 1, or more).
There are 2 problems:
1.) I can't use .limit() correctly. For example, I need only last 5 tasks (84-88), but when I make query, it returns 85, 86, 87, 88 and 88 (it doesn't count 2 entries of task №88 as one).
2.) How can I attach property "count" of table "assoc_tasks_services" in every service in every task?
Please, help me. I'm not good at programming, but I'm trying to understand how can I realize it. Thank you!
Code of initialisation of tables:
Attempt №1 (added property "count" to task. It's the most successful attempt):
Printing result №1:
It returns:
Attempt №2 (added property "count" to service):
Printing result №2:
It returns:
Beta Was this translation helpful? Give feedback.
All reactions