j4mie / paris

A lightweight Active Record implementation for PHP5, built on top of Idiorm.
http://j4mie.github.com/idiormandparis/
996 stars 131 forks source link

does Paris have "left join" ? #67

Closed badpenguin closed 11 years ago

badpenguin commented 11 years ago

Hello, from the doc of Paris i was unable to find out how to translate this from idiorm into paris:

    $article = ORM::for_table('cms_content')->table_alias('c1')
        ->join('cms_content2','c2.cms_id=c1.cms_id','c2')
        ->where('c2.cms_lng', 'IT' )
        ->where('c2.google_slug', 'index' )
        ->find_array();

Its more like a 1to1 because i always filter the detail table by the language code

treffynnon commented 11 years ago

Just do your join against the instance you get back from Model::factory() as you would with ORM::for_table().

badpenguin commented 11 years ago

understood, but what if i want a model that acts as a "view" ? i want my Article model to be the results of the query below, not just a single table

ORM::for_table('cms_content')->table_alias('c1') ->join('cms_content2','c2.cms_id=c1.cms_id','c2') ->where('c2.cms_lng', 'IT' )

treffynnon commented 11 years ago

I am not sure I understand. If you join on another table to your model then you'll get the columns from that table as well.

badpenguin commented 11 years ago

OK i'll make some test about it.

I would also know if there is a way to exec raw query for "update" and "delete" as well as for raw_query(), the doc isn't clean about this too.

badpenguin commented 11 years ago

OK i tested it. Fields from C2 are in the results sets BUT if i try to use "->set" on a field from the joined table "c2" it return the PHP error "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'google_rss_ts' in 'field list' exception generated at idiorm-master/idiorm.php:349 in function "execute" because, from query logs, it try to update the 1st table always

treffynnon commented 11 years ago

That is not supported. Once you use a join it is not possible to then update. The ORM has no idea where that field came from. This will not be implemented.