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 AppendColumn method #2006

Open
wants to merge 1 commit into
base: v10
Choose a base branch
from
Open

Conversation

bohdand-weka
Copy link

No description provided.

@bohdand-weka bohdand-weka changed the title feat: append column method add AppendColumn method Jul 2, 2024
Copy link
Collaborator

@elliotcourant elliotcourant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious what the use case for this is, as the AppendColumn method itself only adds columns that are present on the actual model you're working with. If you are joining between two tables, it would only let you append columns from the base table (whatever was passed to Model(...). Which all of the columns from that model would already be present by default?

Would you be able to provide an example use case for this as well as tests?

orm/query.go Outdated Show resolved Hide resolved
@bohdand-weka
Copy link
Author

bohdand-weka commented Jul 5, 2024

I'm curious what the use case for this is, as the AppendColumn method itself only adds columns that are present on the actual model you're working with. If you are joining between two tables, it would only let you append columns from the base table (whatever was passed to Model(...). Which all of the columns from that model would already be present by default?

Would you be able to provide an example use case for this as well as tests?

The use case is simple.

Imagine we have dynamic columns selection. By default Column() will override all model columns when called first time.

So in our scenario we don't want to override default columns if Column wasn't called with Alias.*, instead we want to just append one more column from our calculation, like aggregation or whatever.
If in our dynamic query there was already Column called - AppendColumn won't touch them, so it does exactly how it's called - appends column.

And it will work for joins as well (as like Column does), why not?

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