Skip to content

Commit ad91ce6

Browse files
committed
refactor(pinia-orm): replace relation.getKey with relation.getResolvedKey
1 parent 920f43b commit ad91ce6

File tree

3 files changed

+3
-19
lines changed

3 files changed

+3
-19
lines changed

packages/pinia-orm/.eslintcache

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

packages/pinia-orm/src/model/attributes/relations/HasMany.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { Schema } from '../../../schema/Schema'
33
import type { Collection, Element } from '../../../data/Data'
44
import type { Query } from '../../../query/Query'
55
import type { Model, PrimaryKey } from '../../Model'
6-
import { isArray } from '../../../support/Utils'
76
import type { Dictionary } from './Relation'
87
import { Relation } from './Relation'
98

@@ -77,11 +76,7 @@ export class HasMany extends Relation {
7776
const dictionary = this.buildDictionary(query.get(false))
7877

7978
models.forEach((model) => {
80-
const key = this.getKey(
81-
isArray(this.localKey)
82-
? this.localKey.map(key => model[key])
83-
: model[this.localKey],
84-
)
79+
const key = this.getResolvedKey(model, this.localKey)
8580

8681
dictionary[key]
8782
? model.$setRelation(relation, dictionary[key])
@@ -94,11 +89,7 @@ export class HasMany extends Relation {
9489
*/
9590
protected buildDictionary (results: Collection<any>): Dictionary {
9691
return this.mapToDictionary(results, (result) => {
97-
const key = this.getKey(
98-
isArray(this.foreignKey)
99-
? this.foreignKey.map(key => result[key as keyof Model]) as PrimaryKey
100-
: result[this.foreignKey as keyof Model] as PrimaryKey,
101-
)
92+
const key = this.getResolvedKey(result, this.foreignKey)
10293
return [key, result]
10394
})
10495
}

packages/pinia-orm/src/model/attributes/relations/Relation.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,6 @@ export abstract class Relation extends Attribute {
125125
}
126126
}
127127

128-
/**
129-
* Generate the index key defined by the primary key or keys (composite)
130-
*/
131-
protected getKey (key: PrimaryKey): string {
132-
return isArray(key) ? `[${key.join(',')}]` : key
133-
}
134-
135128
/**
136129
* Get the index key defined by the primary key or keys (composite)
137130
*/

0 commit comments

Comments
 (0)