From 2b23a82cd0a59358784cab4cc6e0553dce29f4e7 Mon Sep 17 00:00:00 2001 From: Anders Jurisoo Date: Sat, 8 Jun 2019 17:29:57 +0200 Subject: [PATCH] Added HasOne capability --- src/public/js/app.js | 8 +++++++- .../js/fileFactories/Laravel/pipes/ModelPipe.js | 11 +++++++++++ src/templates/HasOneRelationship | 7 +++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/templates/HasOneRelationship diff --git a/src/public/js/app.js b/src/public/js/app.js index 2c0e78b..521a0f6 100644 --- a/src/public/js/app.js +++ b/src/public/js/app.js @@ -208782,7 +208782,13 @@ function (_BasePipe) { }, { key: "relationshipMethods", value: function relationshipMethods(model) { - return [model.relationships.hasMany.map(function (target) { + return [model.relationships.hasOne.map(function (target) { + return _utilities_Template__WEBPACK_IMPORTED_MODULE_0__["default"]["for"]('HasOneRelationship').replace({ + ___TARGET_CLASS___: target.className(), + ___THIS_CLASS___: model.className(), + ___METHOD_NAME___: _utilities_Formatter__WEBPACK_IMPORTED_MODULE_2__["default"].camelCase(target.className()) + }); + }).join(___DOUBLE_LINE_BREAK___), model.relationships.hasMany.map(function (target) { return _utilities_Template__WEBPACK_IMPORTED_MODULE_0__["default"]["for"]('HasManyRelationship').replace({ ___TARGET_CLASS___: target.className(), ___TARGET_CLASS_PLURAL___: _utilities_Formatter__WEBPACK_IMPORTED_MODULE_2__["default"].pluralize(target.className()), diff --git a/src/resources/js/fileFactories/Laravel/pipes/ModelPipe.js b/src/resources/js/fileFactories/Laravel/pipes/ModelPipe.js index c6ee896..92e2514 100644 --- a/src/resources/js/fileFactories/Laravel/pipes/ModelPipe.js +++ b/src/resources/js/fileFactories/Laravel/pipes/ModelPipe.js @@ -47,6 +47,17 @@ export default class ModelPipe extends BasePipe { relationshipMethods(model) { return [ + model.relationships.hasOne.map(target => { + return Template.for('HasOneRelationship').replace({ + ___TARGET_CLASS___: target.className(), + ___THIS_CLASS___: model.className(), + ___METHOD_NAME___: F.camelCase( + target.className() + ), + + }) + }).join(___DOUBLE_LINE_BREAK___), + model.relationships.hasMany.map(target => { return Template.for('HasManyRelationship').replace({ ___TARGET_CLASS___: target.className(), diff --git a/src/templates/HasOneRelationship b/src/templates/HasOneRelationship new file mode 100644 index 0000000..57334d5 --- /dev/null +++ b/src/templates/HasOneRelationship @@ -0,0 +1,7 @@ +/** + * Get the ___TARGET_CLASS___ for the ___THIS_CLASS___. + */ +public function ___METHOD_NAME___() +{ + return $this->hasOne('App\___TARGET_CLASS___'); +} \ No newline at end of file