Orbit Model has error when calling 'a_model:find_*()' and using inject, when the condition is by "id"

9 views
Skip to first unread message

Ryan Pusztai

unread,
Apr 1, 2014, 5:19:32 PM4/1/14
to Kepler Project mailing list
Hi,

I have looked at the code for build_query and am not sure how to fix this issue, but I can't seem to make it work.

When I write this:
self:find_first( "id = ?", { id, inject = { model = hardwareTypesModel, fields = { "id", "name", "identifier" } } } )

I get a database error "LuaSQL: ambiguous column name: id". And it generates this SQL:
select asset.id as id, asset.created_at as created_at, asset.updated_at as updated_at, asset.hardware_type_id as hardware_type_id, asset.serial_number as serial_number, asset.assest_tag as assest_tag, asset.location as location, asset.user_id as user_id, asset.notes as notes, hardware_type.id as hardware_type_id, hardware_type.name as hardware_type_name, hardware_type.identifier as hardware_type_identifier from asset, hardware_type where id  =  1 and hardware_type_id = hardware_type.id

You can see in the WHERE clause that "where id  =  1" is ambiguous. So naturally I changed my condition to:
self:find_first( "asset.id = ?", { id, inject = { model = hardwareTypesModel, fields = { "id", "name", "identifier" } } } )

Then I get this as the error:
.../projects/Goat/sandbox/share/lua/5.1/orbit/model.lua:408: attempt to index field '?' (a nil value)
stack traceback:
.../projects/Goat/sandbox/share/lua/5.1/orbit/model.lua:408: in function <.../projects/Goat/sandbox/share/lua/5.1/orbit/model.lua:393>
(tail call): ?
[C]: in function 'match'
.../projects/Goat/sandbox/share/lua/5.1/orbit/model.lua:392: in function 'build_query'
.../projects/Goat/sandbox/share/lua/5.1/orbit/model.lua:441: in function <.../projects/Goat/sandbox/share/lua/5.1/orbit/model.lua:440>
(tail call): ?
./views/asset.lua:31: in function <./views/asset.lua:30>
(tail call): ?
(tail call): ?
stack traceback:
...x/work/projects/Goat/sandbox/share/lua/5.1/orbit.lua:543: in function 'err'
...ork/projects/Goat/sandbox/share/lua/5.1/coxpcall.lua:35: in function <...ork/projects/Goat/sandbox/share/lua/5.1/coxpcall.lua:33>
(tail call): ?
(tail call): ?
...x/work/projects/Goat/sandbox/share/lua/5.1/orbit.lua:541: in function <...x/work/projects/Goat/sandbox/share/lua/5.1/orbit.lua:522>
(tail call): ?
(tail call): ?

It looks like the condition can not look up the "type" from 'dao.meta[field].type'.
Line 408:

Does anyone know how I should deal with this? I need to simply join/inject so that the hardware_type_id gets the real name not an id.
--
Regards,
Ryan

Ryan Pusztai

unread,
Apr 2, 2014, 2:05:37 PM4/2/14
to Kepler Project mailing list
Hi,


So I found a work around and it is to make sure that I don't use '?' and the array args for value filling. But this is a bug and I think needs a real fix.

Here is what didn't work:
self:find_first( "asset.id = ?", { id, inject = { model = hardwareTypesModel, fields = { "id", "name", "identifier" } } } )

What works:
self:find_first( ("asset.id = %d"):format( id ), { inject = { model = hardwareTypesModel, fields = { "name", "identifier" } } } )
--
Regards,
Ryan
 
Reply all
Reply to author
Forward
0 new messages