Fix: SQL ambiguous column error i contacts søgning - prefikseret med c.
This commit is contained in:
parent
9fe17e7f85
commit
d2c7a8a624
@ -74,17 +74,17 @@ async def get_contacts(
|
||||
params = []
|
||||
|
||||
if search:
|
||||
where_clauses.append("(first_name ILIKE %s OR last_name ILIKE %s OR email ILIKE %s)")
|
||||
where_clauses.append("(c.first_name ILIKE %s OR c.last_name ILIKE %s OR c.email ILIKE %s)")
|
||||
params.extend([f"%{search}%", f"%{search}%", f"%{search}%"])
|
||||
|
||||
if is_active is not None:
|
||||
where_clauses.append("is_active = %s")
|
||||
where_clauses.append("c.is_active = %s")
|
||||
params.append(is_active)
|
||||
|
||||
where_sql = "WHERE " + " AND ".join(where_clauses) if where_clauses else ""
|
||||
|
||||
# Count total
|
||||
count_query = f"SELECT COUNT(*) as count FROM contacts {where_sql}"
|
||||
# Count total (needs alias c for consistency)
|
||||
count_query = f"SELECT COUNT(*) as count FROM contacts c {where_sql}"
|
||||
count_result = execute_query(count_query, tuple(params))
|
||||
total = count_result[0]['count'] if count_result else 0
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user