catfan / Medoo

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

Join problem #357

Closed adminko-svk closed 3 years ago

adminko-svk commented 8 years ago

How can I use JOIN with static values? The second (joining) table has column "xyz" and I need to create JOIN query where "xyz" = 123

Thank you.

adminko-svk commented 8 years ago

I found similar problem here https://github.com/catfan/Medoo/issues/167 Can you please add the modifier [$] to the next release of Medoo?

chrisaybar commented 8 years ago

I ran into the same problem, but came up with a quick solution for v1.0.2 while the developers find a neat way to add support for this.

Note: this quick hack is only meant to get you through the problem if you're in a bind.

Step 1, change line 595 to the following:

BEFORE:

    '"' . (isset($match[ 5 ]) ? $match[ 5 ] : $match[ 3 ]) . '"."' . $value . '"';

AFTER:

    ((substr($value, 0, 4) == '[SV]') ? substr($value, 4) : '`' . (isset($match[ 5 ]) ? $match[ 5 ] : $match[ 3 ]) . '`.`' . $value . '`');

Step 2, add temporary support for denoting a static value by preceeding your join value with "[SV]". For example, in your table join, instead of using something like [ 'fieldName' => 'fieldValue' ] use this instead:

[ 'fieldName' => '[SV]fieldValue' ]

Hope this helps.