From 7aa546f7280f3378288087480cf0013a876ff88e Mon Sep 17 00:00:00 2001 From: Jarriq Rolle Date: Wed, 1 Feb 2023 13:33:57 -0500 Subject: [PATCH 1/2] Get a single column's value from the first result of a query. --- src/masoniteorm/models/Model.py | 1 + src/masoniteorm/query/QueryBuilder.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/masoniteorm/models/Model.py b/src/masoniteorm/models/Model.py index 743c2483..78c8f3d4 100644 --- a/src/masoniteorm/models/Model.py +++ b/src/masoniteorm/models/Model.py @@ -265,6 +265,7 @@ class Model(TimeStampsMixin, ObservesEvents, metaclass=ModelMeta): "with_count", "latest", "oldest", + "value" ) ) diff --git a/src/masoniteorm/query/QueryBuilder.py b/src/masoniteorm/query/QueryBuilder.py index 2e98c5dc..7ae5ec88 100644 --- a/src/masoniteorm/query/QueryBuilder.py +++ b/src/masoniteorm/query/QueryBuilder.py @@ -2277,3 +2277,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] From 7b6a269eac8afb5eaab4e6b24e8d70b3a722699d Mon Sep 17 00:00:00 2001 From: Jarriq Rolle Date: Wed, 1 Feb 2023 13:47:30 -0500 Subject: [PATCH 2/2] Get a single column's value from the first result of a query. --- src/masoniteorm/query/QueryBuilder.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/masoniteorm/query/QueryBuilder.py b/src/masoniteorm/query/QueryBuilder.py index 7ae5ec88..1ac3d4ab 100644 --- a/src/masoniteorm/query/QueryBuilder.py +++ b/src/masoniteorm/query/QueryBuilder.py @@ -1749,6 +1749,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: