gabordemooij / redbean

ORM layer that creates models, config and database on the fly
https://www.redbeanphp.com
2.3k stars 280 forks source link

ID not populating with this SQL select #950

Open Josh5A opened 2 days ago

Josh5A commented 2 days ago

With this sql select I'm getting behavior I didn't expect:

SELECT *
FROM ISSUE i
LEFT JOIN REMOTEID r
ON i.id = r.issue_id
AND r.service_name = 'AskYourPdf'
WHERE r.issue_id IS NULL
AND i.publication_id = 1
LIMIT 1

Output is:

Array
(
    [0] => Array
        (
            [id] => 
            [filename] => Myfile.pdf
            [publication_id] => 1
            [volume] => 01
            [number] => 01
            [chronology_type] => month
            [chronology_year] => 1987
            [chronology_month] => 10
            [service_name] => 
            [remoteid] => 
            [issue_id] => 
        )
)

I would expect id to be populated. When I modify the sql this way, it works:

SELECT *, i.id
FROM ISSUE i
LEFT JOIN REMOTEID r
ON i.id = r.issue_id
AND r.service_name = 'AskYourPdf'
WHERE r.issue_id IS NULL
AND i.publication_id = 1
LIMIT 1

Output is:

Array
(
    [0] => Array
        (
            [id] => 1
            [filename] => Myfile.pdf
            [publication_id] => 1
            [volume] => 01
            [number] => 01
            [chronology_type] => month
            [chronology_year] => 1987
            [chronology_month] => 10
            [service_name] => 
            [remoteid] => 
            [issue_id] => 
        )
)

Is this expected behavior? When I run the first query through MySQL directly rather than through RedBean it works as I expect.

Lynesth commented 2 days ago

How do you call that query?