Skip to content

Commit

Permalink
fix relationship
Browse files Browse the repository at this point in the history
  • Loading branch information
adlius committed Jan 26, 2024
1 parent 2a98e3b commit 7b359dd
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
6 changes: 5 additions & 1 deletion app/models/base-file-item.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { attr } from '@ember-data/model';
import { AsyncBelongsTo, attr, hasMany } from '@ember-data/model';
import { assert } from '@ember/debug';
import { computed } from '@ember/object';
import { or } from '@ember/object/computed';
import { Link } from 'jsonapi-typescript';

import getHref from 'ember-osf-web/utils/get-href';
import { addQueryParam } from 'ember-osf-web/utils/url-parts';
import CedarMetadataRecordModel from 'ember-osf-web/models/cedar-metadata-record';
import OsfModel, { OsfLinks } from './osf-model';

export enum FileItemKinds {
Expand All @@ -28,6 +29,9 @@ export default class BaseFileItem extends OsfModel {
@attr() links!: BaseFileLinks;
@attr('fixstring') kind?: FileItemKinds;

@hasMany('cedar-metadata-record', { inverse: 'target'})
cedarMetadataRecords!: AsyncBelongsTo<CedarMetadataRecordModel> & CedarMetadataRecordModel;

// Override in subclasses to set `true` when appropriate
isNode = false;
isProvider = false;
Expand Down
2 changes: 1 addition & 1 deletion app/models/cedar-metadata-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class CedarMetadataRecordModel extends OsfModel {
@belongsTo('cedar-metadata-template', { inverse: null })
template!: AsyncBelongsTo<CedarMetadataTemplateModel> | CedarMetadataTemplateModel;

@belongsTo('osf-model', { polymorphic: true })
@belongsTo('base-file-item', { inverse: 'cedarMetadataRecords' , polymorphic: true })
target!: (AsyncBelongsTo<AbstractNodeModel> | AbstractNodeModel) | (AsyncBelongsTo<FileModel> | FileModel);
}

Expand Down
4 changes: 0 additions & 4 deletions app/models/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Link } from 'jsonapi-typescript';

import { FileReference } from 'ember-osf-web/packages/registration-schema';
import getHref from 'ember-osf-web/utils/get-href';
import CedarMetadataRecordModel from 'ember-osf-web/models/cedar-metadata-record';

import PreprintModel from 'ember-osf-web/models/preprint';
import AbstractNodeModel from './abstract-node';
Expand Down Expand Up @@ -62,9 +61,6 @@ export default class FileModel extends BaseFileItem {
// eslint-disable-next-line max-len
target!: (AsyncBelongsTo<AbstractNodeModel> & AbstractNodeModel) | (AsyncBelongsTo<PreprintModel> & PreprintModel) | (AsyncBelongsTo<DraftNode> & DraftNode);

@hasMany('cedar-metadata-record', { inverse: 'target'})
cedarMetadataRecords!: AsyncBelongsTo<CedarMetadataRecordModel> & CedarMetadataRecordModel;

// BaseFileItem override
isFileModel = true;

Expand Down
4 changes: 0 additions & 4 deletions app/models/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { htmlSafe } from '@ember/template';
import { tracked } from '@glimmer/tracking';
import { buildValidations, validator } from 'ember-cp-validations';
import Intl from 'ember-intl/services/intl';
import CedarMetadataRecordModel from 'ember-osf-web/models/cedar-metadata-record';

import config from 'ember-osf-web/config/environment';
import { task } from 'ember-concurrency';
Expand Down Expand Up @@ -167,9 +166,6 @@ export default class NodeModel extends AbstractNodeModel.extend(Validations, Col
@hasMany('node', { inverse: 'forkedFrom', polymorphic: true })
forks!: AsyncHasMany<NodeModel>;

@hasMany('cedar-metadata-record', { inverse: 'target'})
cedarMetadataRecords!: AsyncBelongsTo<CedarMetadataRecordModel> & CedarMetadataRecordModel;

@belongsTo('node', { inverse: 'forks', polymorphic: true })
forkedFrom!: (AsyncBelongsTo<NodeModel> & NodeModel) | (AsyncBelongsTo<RegistrationModel> & RegistrationModel);

Expand Down

0 comments on commit 7b359dd

Please sign in to comment.