Skip to content

Commit

Permalink
Merge pull request #838 from JarriqTheTechie/feature/value
Browse files Browse the repository at this point in the history
Adds function value and sole_value to QueryBuilder & Model.
  • Loading branch information
josephmancuso authored Sep 30, 2023
2 parents 1edbb44 + 7b6a269 commit f2d57f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/masoniteorm/models/Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ class Model(TimeStampsMixin, ObservesEvents, metaclass=ModelMeta):
"with_count",
"latest",
"oldest",
"value"
)
)

Expand Down
6 changes: 6 additions & 0 deletions src/masoniteorm/query/QueryBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1754,6 +1754,9 @@ def sole(self, query=False):

return result.first()

def sole_value(self, column: str, query=False):
return self.sole()[column]

def first_where(self, column, *args):
"""Gets the first record with the given key / value pair"""
if not args:
Expand Down Expand Up @@ -2282,3 +2285,6 @@ def oldest(self, *fields):
fields = ("created_at",)

return self.order_by(column=",".join(fields), direction="ASC")

def value(self, column: str):
return self.get().first()[column]

0 comments on commit f2d57f7

Please sign in to comment.