clarkwinkelmann Ooh I see, I'll put my code below, thanks! 🙂
extend.php
(new Extend\Model(User::class))
->hasOne('relation', 'Digitalam\Relation\Relation'),
(new Extend\Routes('api'))
->get('/relation', 'relation.index', ListRelationsController::class)
->get('/relation/{id:[0-9]+}', 'relation.show', ShowRelationController::class)
->post('/relation', 'relation.create', CreateRelationController::class)
->patch('/relation/{id:[0-9]+}', 'relation.update', UpdateRelationController::class),
(new Extend\ApiSerializer(BasicUserSerializer::class))
->hasOne('relation', RelationSerializer::class),
(new Extend\ApiController(ListUserController::class))
->addInclude('relation'),
(new Extend\ApiController(ShowUserController::class))
->addInclude('relation'),
(new Extend\ApiController(UpdateUserController::class))
->addInclude('relation'),
(new Extend\ApiController(CreateUserController::class))
->addInclude('relation'),
Relation.js
export default class Relation extends Model {
id = Model.attribute("id");
name = Model.attribute("name");
index.js (In app.initializers.add)
app.store.models["Relation"] = Relation; // Imported Relations model already
User.prototype.Relation = Model.hasOne("Relation");
override(UserCard.prototype, "view", function (view) {
const relationName = user.relation().name()
const relationId = user.relation().id()
return m(myComponent, {/*attrs*/});
}
So far, visiting the api routes of my model, it can post, patch and get just as normal.