Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excessive a.* clause #328

Open
KarelWintersky opened this issue Jan 4, 2022 · 3 comments
Open

Excessive a.* clause #328

KarelWintersky opened this issue Jan 4, 2022 · 3 comments

Comments

@KarelWintersky
Copy link

$query = new \Envms\FluentPDO\Query($this->pdo);
$query = $query
    ->from('articles AS a')
    ->select("a.id, a.title, a.cdate")
    ->where("a.s_hidden = 0")
    ->where("a.s_draft = 0")
    ->leftJoin("articles_keys AS ak ON ak.aid = a.id")
    ->orderBy("a.cdate DESC")
    ->groupBy("a.id");

var_dumo( $query->getQuery() );

Have a result:

SELECT a.*, a.id, a.title, a.cdate
FROM articles AS a
    LEFT JOIN articles_keys AS ak ON ak.aid = a.id
WHERE a.s_hidden = 0
    AND a.s_draft = 0
GROUP BY a.id
ORDER BY a.cdate DESC
@azurre
Copy link
Contributor

azurre commented Jan 4, 2022

@KarelWintersky
Just add second argument overrideDefault to select()

->select("a.id, a.title, a.cdate", true)

@KarelWintersky
Copy link
Author

... and no any info at readme... :-(

@darkalchemy
Copy link

If you don't want everything from the table, use ->select(null), this was documented in the past.

$query = new \Envms\FluentPDO\Query($this->pdo);
$query = $query
    ->from('articles AS a')
    ->select(null)
    ->select("a.id, a.title, a.cdate")
    ->where("a.s_hidden = 0")
    ->where("a.s_draft = 0")
    ->leftJoin("articles_keys AS ak ON ak.aid = a.id")
    ->orderBy("a.cdate DESC")
    ->groupBy("a.id");

var_dumo( $query->getQuery() );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants