We're updating the issue view to help you get more done. 

BaseModel find generates wrong SQL

Description

The find method in BaseModel generates wrong SQL when querying for list items of list attributes and possibly in other cases too.

Repro:
1. Create a user defined list with some items
2. Add an attribute of type list to any object type and use the list created in step 1 as source.
3. Add a UI bundle to change the list value on that object type
4. Edit/Create an object of that type, chose any value from the list
5. Save the object

Expected:
The list attribute is persisted.
Actual:
The list attribute is not persisted. If the attribute is required, the following error message is shown: "Value 158 for Category [category] is invalid." Where 158 is the item_id and category is the attribute.

The reason is that ca_list_items::find() doesn't return anything when querying for the list item (by item_id and list_id). The actual bug is in the BaseModel->find() method. The $pa_values array is flattened in a weird way, resulting in an unwanted where clause.

I have attached a screenshot that shows $pa_values and $vm_value when adding the where clause for type_id. $vm_value should be null in this case but is array(0 => 0) instead.

The generated SQL looks like
SELECT * FROM ca_list_items WHERE (deleted = 0) AND ((item_id = 158) and (list_id = 43) and (type_id IN (0)))
but should be
SELECT * FROM ca_list_items WHERE (deleted = 0) AND ((item_id = 158) and (list_id = 43)

Environment

None

Activity

Show:
User known
March 8, 2015, 7:52 PM

Have you done a pull really recently? This should have been fixed in f2e43c24597b261bd7083b2470d9304cd374f303 (https://github.com/collectiveaccess/providence/commit/f2e43c24597b261bd7083b2470d9304cd374f303)

Jasper
March 8, 2015, 8:04 PM

Not that recently.

Feel free to close this as fixed.

User known
March 8, 2015, 8:40 PM

Well it was my bug Sorry!

Fixed

Assignee

User known

Reporter

Jasper

Labels

None

Components

Affects versions

Priority

Blocker
Configure