Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model extensions interface #59

Merged
merged 5 commits into from
Mar 30, 2023
Merged

Model extensions interface #59

merged 5 commits into from
Mar 30, 2023

Conversation

ridafkih
Copy link
Owner

@ridafkih ridafkih commented Mar 30, 2023

This PR adds the ability to use the extendModel function to extend the model to include the attributes of the extended model provided into the function.

Extending Models

Sometimes one model is derivative of another, and the extension feature can be quite useful for this.

If we want to extend the PostModel to create an ImagePostModel which has all its old properties but with an imageUrl string column, we can do so without having to re-write every single other attribute.

// ./models/ImagePostModel.model.ts

import { extendModel } from "schemix";

import PostModel from "./Post.model";

export default extendModel(PostModel, (ImagePostModel) => {
  ImagePostModel.string("imageUrl");
});

@ridafkih ridafkih merged commit ff87696 into main Mar 30, 2023
@ridafkih ridafkih deleted the model-extensions-interface branch March 30, 2023 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant