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
161 stars 47 forks source link

Returning all fields after creation even if it's NULL #827

Closed Marlysson closed 1 year ago

Marlysson commented 1 year ago

Describe the bug Is there a way to hydrate model that includes null fields? Because if I load the model from DB, all fields that are null are not included in Model.attributes Even Model.all_attributes() doesn't give me all attributes hydrated with None values.

To Reproduce

result = Model.create(field=value)
result.__attributes__ # nullable field with NULL values will not appear in dict

Expected behavior

result.__attributes__ -> {...., {"nullable_field": None}}
josephmancuso commented 1 year ago

Theres really not a great way to do this with consistency. The problem is if you don't supply the fields, we don't know what the defaults will be. Not every field you don't specify will be nullable. Some fields could default to any value you specify in the migration or table.