Add __visible__ to model serialization
See original GitHub issueRight now, when serializing a model it will put all model fields + properties (what has been defined in append).
I have seen that we can start from a dict given as argument of the serialize() method, but I have not really see a way to define how the model should be serialized without using Masonite API.
Here I just want - on the fly - to serialize e.g. the User model with three attributes: id, name, email. name is a property.
I feel we would like to do something like:
User.find(1).serialize(["id", "name", "email"]) # {"id": 1, "name": "John Doe", "email": johndoe@example.com}
OR we could also add something in the model such as : __serialized_fields__ = ["id", "name", "email"]
If you confirm it’s not possible right now and this implementation is correct, I’ll open a PR. We should also update documentation to explain model serialization I have not seen it in orm docs.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (8 by maintainers)

Top Related StackOverflow Question
yeah that’s fine. I deff see a valid scenario for both. We do the same exact thing for the fillable and guarded attributes
Sure it might be too simple for you so if its not taken by someone on Friday go for it 😃