ClanCats / Hydrahon

🐉 Fast & standalone PHP MySQL Query Builder library.
https://clancats.io/hydrahon/master/
MIT License
278 stars 58 forks source link

hello I would like a help with an INNER JOIN #41

Closed zehenrique08 closed 4 years ago

zehenrique08 commented 4 years ago

I am not able to reproduce following sql using HYDRAHON

SELECT a.idproduto AS id ,b.nome AS nome ,b.valor AS valor ,a.qauntidade AS qauntidade FROM quantosa INNER JOIN produtos b ON a.idproduto = b.id where a.idcliente = 37

joaosn commented 4 years ago

I have the same problem!!

mario-deluna commented 4 years ago

Hi there.

$h
    ->table('quantos as a')
    ->select([
        'a.idproduto as id',
        'b.name as nome',
        'b.valor as valor',
        'b.qauntidade as qauntidade',
    ])
    ->innerJoin('produtos as b', 'a.idproduto', '=', 'b.id')
    ->where('a.idcliente', 37)
    ->get();

produces the following query:

SELECT `a`.`idproduto` AS `id`,
       `b`.`name` AS `nome`,
       `b`.`valor` AS `valor`,
       `b`.`qauntidade` AS `qauntidade`
FROM `quantos` AS `a`
INNER JOIN `produtos` AS `b` ON `a`.`idproduto` = `b`.`id`
WHERE `a`.`idcliente` = ?

Is this what you are trying to achieve?

joaosn commented 4 years ago

Hi

$dados = Quanto::select([
    'idproduto as id',
    'b.name as nome',
    'b.valor as valor',
    'b.qauntidade as qauntidade',
])
->innerJoin('produtos as b', 'idproduto', '=', 'b.id')
->where('idcliente', $id)
->get();`

could you really give me an example using Static method?

mario-deluna commented 4 years ago

The class Quanto is not a part of hydrahon so without further information I cannot help you here. The only thing I see is that there is no table provided?

joaosn commented 4 years ago

hello friend thank you for having answered, about 'Quanto' he and referring to the table created there in the database

for me to do simple select in the table I do like this

Quanto::select()->get();

instead of so

$h->table(quanto)->select()->get();

joaosn commented 4 years ago

already got a friend thanks for responding with your code got a better understanding of the inner join syntax $dados = Quanto::select([ 'idproduto as id', 'b.nome as nome', 'b.valor as valor', 'qauntidade as qauntidade', ]) ->innerJoin('produtos as b', 'idproduto', '=', 'b.id') ->where('idcliente', $id) ->execute();

mario-deluna commented 4 years ago

Im closing this Issue now. Let me know if the issue persists.