xavierlacot / joli.js

joli.js is an Activerecord-like javascript ORM, particularly suited for being used in the Appcelerator Titanium Mobile framework.
MIT License
267 stars 60 forks source link

Retrieving wrong field in a query with join. #40

Open domecq opened 11 years ago

domecq commented 11 years ago

Hello, To be honest I don't know if it is an issue or I am doing something wrong. This is my query:

        var q = new joli.query()
          .select('item.*')
          .from('orderitem')
          .order(['orderitem_id desc'])
          .join('orders','orders.order_id','orderitem.order_id')
          .join('item','item.item_id','orderitem.item_id');

           var items = q.execute();

So far I can see Joli is properly constructing the query :

select item.* 
from orderitem left outer join orders on orders.order_id = orderitem.order_id 
left outer join item on item.item_id = orderitem.item_id 
order by orderitem_id desc

The problem is that items collection only return orderitem's fields rather than the item's fields.

This is what each returning record has:

I/TiAPI   ( 1598):  key in _options
I/TiAPI   ( 1598):  key in _data
I/TiAPI   ( 1598):  key in _originalData
I/TiAPI   ( 1598):  key in isNew
I/TiAPI   ( 1598):  key in orderitem_id
I/TiAPI   ( 1598):  key in order_id
I/TiAPI   ( 1598):  key in item_id
I/TiAPI   ( 1598):  key in item_quantity
I/TiAPI   ( 1598):  key in beer_quantity
I/TiAPI   ( 1598):  key in orderitem_type
I/TiAPI   ( 1598):  key in beer_id

Those are all fields belonging to orderitem instead of item table as I expected.

Thanks! nico.

OwenMelbz commented 10 years ago

Hi Nico, I've got this exact problem at the moment, was wondering if you've sorted this and how? Otherwise i'll have to start modifying the joli core.