creatoro / jelly

A flexible ORM for Kohana 3.1+
http://jelly.jonathan-geiger.com
MIT License
72 stars 13 forks source link

select with join alias #61

Closed orloffv closed 13 years ago

orloffv commented 13 years ago

Jelly::query('page')->select_column('section.*')->join(array('page', 'section'), 'inner')->execute()->as_array();

generate sql error "Database_Exception [ 1146 ]: Table 'gds_dev.section' doesn't exist [ SELECT section.* FROM page AS page INNER JOIN section AS section ON (page.id = section.pid) ]"

leth commented 13 years ago

What are these changes for? I don't understand what you're doing in your example code.

Also, have you run these changes through the test suite, to check they don't break anything else? It'd be good if you could make a unit test for this (and a pull request for it too).

Thanks

orloffv commented 13 years ago

sry Jelly::query('page')->select_column('section.*')->join(array('page', 'section'), 'inner')->on('page.id', '=', 'section.pid')->execute()->as_array();

maybe on weekends i create tests

leth commented 13 years ago

So you have a page table which has a relationship with itself. Each page has many sections, is that right?

Jelly isn't designed to be able to return a record and a 1-many relationship in the same query.

Alternatively you could create a parent section relationship, and query for all sections and specify that the parent post be included using with(...).

AFAIK, in either approach, Jelly won't spot the duplicate instances of the same model & primary key.