-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flatten belongs-to relationship fix: implicit inverse key gen needs to utilize the related type for uniqueness
- Loading branch information
Showing
36 changed files
with
1,658 additions
and
1,242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { graphFor } from '@ember-data/record-data/-private'; | ||
import { recordIdentifierFor } from '@ember-data/store'; | ||
|
||
type CoreStore = import('@ember-data/store/-private/system/core-store').default; | ||
type BelongsToRelationship = import('@ember-data/record-data/-private').BelongsToRelationship; | ||
type ManyRelationship = import('@ember-data/record-data/-private').ManyRelationship; | ||
type Relationship = import('@ember-data/record-data/-private').Relationship; | ||
type RecordDataStoreWrapper = import('@ember-data/store/-private').RecordDataStoreWrapper; | ||
type StableRecordIdentifier = import('@ember-data/store/-private/ts-interfaces/identifier').StableRecordIdentifier; | ||
type RelationshipDict = import('@ember-data/store/-private/ts-interfaces/utils').ConfidentDict<Relationship>; | ||
|
||
export function getRelationshipStateForRecord( | ||
record: { store: CoreStore }, | ||
propertyName: string | ||
): BelongsToRelationship | ManyRelationship | Relationship { | ||
const identifier = recordIdentifierFor(record); | ||
return graphFor(record.store._storeWrapper).get(identifier, propertyName); | ||
} | ||
|
||
export function hasRelationshipForRecord( | ||
record: { | ||
store: CoreStore; | ||
}, | ||
propertyName: string | ||
): boolean { | ||
const identifier = recordIdentifierFor(record); | ||
const relationships = graphFor(record.store._storeWrapper).identifiers.get(identifier); | ||
return relationships ? propertyName in relationships : false; | ||
} | ||
|
||
export function implicitRelationshipsFor( | ||
storeWrapper: RecordDataStoreWrapper, | ||
identifier: StableRecordIdentifier | ||
): RelationshipDict { | ||
const rels = graphFor(storeWrapper).identifiers.get(identifier); | ||
if (!rels) { | ||
throw new Error(`Expected at least one relationship to be populated`); | ||
} | ||
let implicits = Object.create(null); | ||
Object.keys(rels).forEach((key) => { | ||
let rel = rels[key]!; | ||
if (rel.definition.isImplicit) { | ||
implicits[key] = rel; | ||
} | ||
}); | ||
return implicits; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.