From 67f3d10d1172345b3797eb57e93b9adaabf26f0e Mon Sep 17 00:00:00 2001 From: Stas Arshanski Date: Fri, 6 Dec 2024 06:30:22 +0200 Subject: [PATCH 1/4] Update attribute.template on generate model add support for collection attribute (Assosiations) --- lib/core-generators/model/templates/attribute.template | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/core-generators/model/templates/attribute.template b/lib/core-generators/model/templates/attribute.template index 6814fae7..b6e10fcb 100644 --- a/lib/core-generators/model/templates/attribute.template +++ b/lib/core-generators/model/templates/attribute.template @@ -8,7 +8,14 @@ * */ %> -<%if (lang === 'js') {%> <%= name %>: { type: '<%= type %>' } +<% if (lang === 'js') { %> +<%= name %>: { + <% if(type.includes(['[',']')) { %> + collection: '<%= type.replace('[','').replace(']','').toLowerCase() %>' + <% } else { %> + type: '<%= type %>' + <% } %> +} <%} else if (lang === 'coffee'){ %> <%=name%>: type: '<%= type %>' <%}%> From 93428d6c5a4645ff5c4404796a597bc07ab3e0ba Mon Sep 17 00:00:00 2001 From: Stas Arshanski Date: Fri, 6 Dec 2024 06:43:32 +0200 Subject: [PATCH 2/4] Update attribute.template --- lib/core-generators/model/templates/attribute.template | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/core-generators/model/templates/attribute.template b/lib/core-generators/model/templates/attribute.template index b6e10fcb..16558d86 100644 --- a/lib/core-generators/model/templates/attribute.template +++ b/lib/core-generators/model/templates/attribute.template @@ -9,13 +9,17 @@ */ %> <% if (lang === 'js') { %> -<%= name %>: { + <%= name %>: { <% if(type.includes(['[',']')) { %> - collection: '<%= type.replace('[','').replace(']','').toLowerCase() %>' + collection: '<%= type.replace('[','').replace(']','').toLowerCase() %>' <% } else { %> - type: '<%= type %>' + type: '<%= type %>' <% } %> } <%} else if (lang === 'coffee'){ %> <%=name%>: +<% if(type.includes(['[',']')) { %> + collection: '<%= type.replace('[','').replace(']','').toLowerCase() %>' + <% } else { %> type: '<%= type %>' + <% } %> <%}%> From b1b6c202663ab8d91de18266570cab68ae2871f3 Mon Sep 17 00:00:00 2001 From: Stas Arshanski Date: Fri, 6 Dec 2024 06:56:58 +0200 Subject: [PATCH 3/4] Update attribute.template add support for single model assosiation --- .../model/templates/attribute.template | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/core-generators/model/templates/attribute.template b/lib/core-generators/model/templates/attribute.template index 16558d86..cc00175a 100644 --- a/lib/core-generators/model/templates/attribute.template +++ b/lib/core-generators/model/templates/attribute.template @@ -10,15 +10,21 @@ %> <% if (lang === 'js') { %> <%= name %>: { - <% if(type.includes(['[',']')) { %> - collection: '<%= type.replace('[','').replace(']','').toLowerCase() %>' + <% + if(type.includes(['[',']')) { + type = type.replace('[','').replace(']','').toLowerCase(); + %> + <% if(type[type.length-1] == 's') { %>collection:<% } else { %>model:<% } %> '<%= type %>' <% } else { %> type: '<%= type %>' <% } %> } <%} else if (lang === 'coffee'){ %> <%=name%>: -<% if(type.includes(['[',']')) { %> - collection: '<%= type.replace('[','').replace(']','').toLowerCase() %>' +<% + if(type.includes(['[',']')) { + type = type.replace('[','').replace(']','').toLowerCase(); +%> + <% if(type[type.length-1] == 's') { %>collection:<% } else { %>model:<% } %> '<%= type %>' <% } else { %> type: '<%= type %>' <% } %> From be0f6c113d29dacdc675347758144f8eea169a03 Mon Sep 17 00:00:00 2001 From: Stas Arshanski Date: Fri, 6 Dec 2024 07:24:14 +0200 Subject: [PATCH 4/4] Update attribute.template --- lib/core-generators/model/templates/attribute.template | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core-generators/model/templates/attribute.template b/lib/core-generators/model/templates/attribute.template index cc00175a..043c3329 100644 --- a/lib/core-generators/model/templates/attribute.template +++ b/lib/core-generators/model/templates/attribute.template @@ -14,7 +14,7 @@ if(type.includes(['[',']')) { type = type.replace('[','').replace(']','').toLowerCase(); %> - <% if(type[type.length-1] == 's') { %>collection:<% } else { %>model:<% } %> '<%= type %>' + <% if(name[name.length-1] == 's') { %>collection:<% } else { %>model:<% } %> '<%= type %>' <% } else { %> type: '<%= type %>' <% } %> @@ -24,7 +24,7 @@ if(type.includes(['[',']')) { type = type.replace('[','').replace(']','').toLowerCase(); %> - <% if(type[type.length-1] == 's') { %>collection:<% } else { %>model:<% } %> '<%= type %>' + <% if(name[name.length-1] == 's') { %>collection:<% } else { %>model:<% } %> '<%= type %>' <% } else { %> type: '<%= type %>' <% } %>