MasoniteFramework / orm

Masonite ORM is a beautiful Python ORM. It's also a nearly drop in replacement of the Orator ORM
https://orm.masoniteproject.com
MIT License
160 stars 47 forks source link

Added only to Model #866

Closed JarriqTheTechie closed 6 months ago

JarriqTheTechie commented 7 months ago

Added

Usage

User.first_or_create(
      {"email": "abc@123.com"},
      {"email": "abc@123.com", "password": "password123"}
  ).only([
      "id",
      "email",
  ])

this would return the following

{'id': 1, 'email': 'abc@123.com'}

In addition to the above usage, you can also use this as a way to remap data. We can alias attributes so that the results can match its destination. Example usage

User.first_or_create(
      {"email": "abc@123.com"},
      {"email": "abc@123.com", "password": "password123"}
  ).only([
      "id as UserIdentifier",
      "email as EmailAddress",
  ])

this would return the following

{'UserIdentifier': 2, 'EmailAddress': 'abc@123.com'}
josephmancuso commented 6 months ago

made a small change here if you just want to pull 1 column by not needing to pass a list

User.first_or_create(
      {"email": "abc@123.com"},
      {"email": "abc@123.com", "password": "password123"}
  ).only("email")
josephmancuso commented 6 months ago

and i added tests