prisma-laravel-migrate 3.0.4 → 3.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -615,18 +615,21 @@ You can attach them either:
615
615
 
616
616
  ## Summary of Directives
617
617
 
618
- | Directive | Scope | Purpose |
619
- | ------------------------------------------------------------------------------------------- | -------------------------------------- | ----------------------------------------------------------------------------------- |
620
- | `@fillable` | Field **or** `@fillable{...}` on model | Adds field(s) to `$fillable`. |
621
- | `@hidden` | Field **or** `@hidden{...}` on model | Adds field(s) to `$hidden`. |
622
- | `@guarded` | Field **or** `@guarded{...}` on model | Adds field(s) to `$guarded`. |
623
- | `@cast{…}` | Field | Adds a cast to `$casts`. |
624
- | `@type{ import:'…', type:'…' }` | Field | Exposes a PHP/interface type hint for downstream tooling. |
625
- | `@with` / `@with(a,b,…)` | Field / Model | Eager-load relations via `$with`. |
626
- | `@trait:…` `@extend:…` `@implements:…` `@observer:…` `@factory:…` `@touch{…}` `@appends{…}` | Model | Class customization & extras. |
627
- | **`@local` (new)** | **Relation Field** | **Skip generating that specific relation method** on the model. Replaces `@ignore`. |
628
- | **`@silent` (new)** | **Model / Enum** | **Do not emit files** for this entity (model + migration / enum). |
629
- | **`@morph(…)` (new)** | **Model** | Declare owner-side polymorphic relations; child-side `morphTo` is auto. |
618
+ | Directive | Scope | Purpose |
619
+ | ------------------------------------------------------------------------------------------- | --------------------------------------- | ---------------------------------------------------------------------------------------- |
620
+ | `@fillable` | Field **or** `@fillable{}` on model | Adds field(s) to `$fillable`. |
621
+ | `@hidden` | Field **or** `@hidden{}` on model | Adds field(s) to `$hidden`. |
622
+ | `@guarded` | Field **or** `@guarded{}` on model | Adds field(s) to `$guarded`. |
623
+ | `@cast{…}` | Field | Adds a cast entry to `$casts`. |
624
+ | `@type{ import:'…', type:'…' }` | Field | Exposes a PHP/interface type hint for downstream tooling. |
625
+ | `@with` / `@with(a,b,…)` | Field / Model | Marks relations to eager-load via `$with`. |
626
+ | `@trait:…` `@extend:…` `@implements:…` `@observer:…` `@factory:…` `@touch{…}` `@appends{…}` | Model | Class customization & extras (traits, parents, observers, factories, touches, appends). |
627
+ | `@local` | Relation Field | Skip generating that **specific relation method** on the model. Replaces `@ignore`. |
628
+ | `@silent` | Model / Enum | Do **not** emit files for this entity (model + migration / enum). |
629
+ | `@morph(…)` | Model | Declare owner-side polymorphic relations; child-side `morphTo` is auto-detected. |
630
+ | `@pivot` / `@pivot(a,b,…)` | Pivot **model** and/or scalar **fields**| Explicitly mark extra pivot columns to include in generated `withPivot(…)` chains. |
631
+ | `@withTimestamps` | Pivot **model** / relation **field** | Instructs the generator to append `->withTimestamps()` on the relation definition. |
632
+ | `@pivotAlias(name)` | Pivot **model** | Sets the pivot attribute alias; generator should add `->as('name')` on the relation. |
630
633
 
631
634
  > **Syntax options**
632
635
  > • Inline: `balance Decimal /// @fillable @cast{decimal:2}`
@@ -86,11 +86,15 @@ export function extractListRelationKeys(dmmf, model, field) {
86
86
  .filter((name) => !keyFieldNames.has(name));
87
87
  // 4) @withTimestamps is a pure flag: "call ->withTimestamps()"
88
88
  const withTimestamps = /@withTimestamps\b/i.test(pivotDoc);
89
+ // 5) @pivotAlias(name) for optional alias - take the first name from listFrom
90
+ const pivotAliasNames = listFrom(pivotDoc, "pivotAlias");
91
+ const pivotAlias = pivotAliasNames.length > 0 ? pivotAliasNames[0].trim() || undefined : undefined;
89
92
  return {
90
93
  kind: "belongsToMany",
91
94
  mode: "explicit",
92
95
  target: target.name,
93
96
  pivotTable: dbNameOf(pivot),
97
+ pivotAlias,
94
98
  pivotColumns,
95
99
  withTimestamps,
96
100
  pivotLocal: relToMe.relationFromFields ?? [],
@@ -135,12 +139,16 @@ export function buildRelationsForModel(dmmf, model) {
135
139
  }
136
140
  else if (keys.kind === "belongsToMany" && keys.mode === "explicit") {
137
141
  const chainParts = [];
142
+ // 1) alias first: ->as('alias')
143
+ if (keys.pivotAlias) {
144
+ chainParts.push(`as('${keys.pivotAlias}')`);
145
+ }
146
+ // 2) withPivot(...)
138
147
  if (keys.pivotColumns && keys.pivotColumns.length > 0) {
139
- const cols = keys.pivotColumns
140
- .map((c) => `'${c}'`) // quote column names for PHP
141
- .join(", ");
148
+ const cols = keys.pivotColumns.map((c) => `'${c}'`).join(", ");
142
149
  chainParts.push(`withPivot(${cols})`);
143
150
  }
151
+ // 3) withTimestamps()
144
152
  if (keys.withTimestamps) {
145
153
  chainParts.push("withTimestamps()");
146
154
  }
@@ -155,6 +163,7 @@ export function buildRelationsForModel(dmmf, model) {
155
163
  pivotForeign: keys.pivotForeign,
156
164
  pivotColumns: keys.pivotColumns,
157
165
  withTimestamps: keys.withTimestamps,
166
+ pivotAlias: keys.pivotAlias, // <— NEW, if you want it in defs
158
167
  localKey: keys.local,
159
168
  foreignKey: keys.foreign,
160
169
  targetModelName: keys.target,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-laravel-migrate",
3
- "version": "3.0.4",
3
+ "version": "3.0.5",
4
4
  "description": "Generate laravel migrations and/or models using prisma files",
5
5
  "bin": {
6
6
  "prisma-laravel-migrations": "./dist/cli/migrator.index.js",