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

Add alias support for select in SQL builder #7

Merged
merged 1 commit into from
Oct 27, 2023

Conversation

martok
Copy link
Contributor

@martok martok commented Oct 26, 2023

This adds table name aliasing capabilites to the Select::from() clause, using the same shorthand as in the various Select::join(). A simple test case is included.

This can be very useful for self-joins in tree-like structures, where otherwise columns would be ambiguous or require re-stating the table name very often. An example from my project, using the Record classes to avoid hard-coding table names:

$q->select(['a.id'])
  ->from(['a' => Inodes::table()])
  ->leftJoin(['b' => Inodes::table()], ['b.id' => 'a.parent_id'])
  ...

Result (wrapped for readability):

SELECT "a"."id"
FROM "inodes" AS "a"
LEFT JOIN "inodes" AS "b" ON ("b"."id" = "a"."parent_id")
...

@nicksagona nicksagona merged commit 19904bf into popphp:master Oct 27, 2023
2 checks passed
@nicksagona
Copy link
Collaborator

Just merged it. Thanks for the contribution. FYI - Pop PHP v5 is close to being released, which includes the next version of this component, v6.

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

Successfully merging this pull request may close these issues.

2 participants