catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.84k stars 1.15k forks source link

JOIN clause error #21

Closed spiider closed 10 years ago

spiider commented 11 years ago

Hello,

when we use condition join we cant select atribute the 'ON' statement and 'WHERE' clause

HelloLudger commented 11 years ago

Hi, I've encountered the same problem and am also interested in a solution.

Great library, btw.

catfan commented 11 years ago

@spiider @lorion84 This feature is experimental on Medoo 0.8.5. But better support on version 0.8.6 [#develop] on dev branch released recently. Try it:)

'[>]' = 'LEFT JOIN'
'[<]' = 'RIGHT JOIN'
'[<>]' = 'FULL JOIN'
'[><]' = 'INNER JOIN'
$database->select('post', [
    // if post.author_id is equal account.user_id
    '[>]account' => ['author_id' => 'user_id'],

    // USING user_id, if post.user_id is equal album.user_id
    '[>]album' => 'user_id',

    // USING ('user_id', 'avatar_id'), if post.user_id is equal photo.user_id and post.avatar_id is equal photo.avatar_id
    '[>]photo' => ['user_id', 'avatar_id']
], [
    'post.post_id',
    'post.title',
    'account.city'
], [
    'post.user_id' => 100,
    'ORDER' => 'post.post_id DESC',
    'LIMIT' => 50
]);

echo $database->last_query();