question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide convenience types for hasMany and belongsTo relationships

See original GitHub issue

Which package(s) does this enhancement pertain to?

Please write a user story for this feature

As a developer, I want types importable from @ember-data/model that can be used to type model properties that represent async hasMany and belongsTo relationships.

These currently require importing from ember-data and using the somewhat esoteric PromiseManyArray (for hasMany) and PromiseObject (for belongsTo), e.g.

import Model, { hasMany, belongsTo } from `@ember-data/model`;
import DS from 'ember-data';

export default class MyModel extends Model {
  @hasMany('foo') foos!: DS.PromiseManyArray<Foo>;
  @belongsTo('bar') bar!: DS.PromiseObject<Bar> & Bar;
}

It would be nicer to have:

import Model, { hasMany, HasMany, belongsTo, BelongsTo } from `@ember-data/model`;

export default class MyModel extends Model {
  @hasMany('foo') foos!: HasMany<Foo>;
  @belongsTo('bar') bar!: BelongsTo<Bar>;
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jamescdaviscommented, Dec 9, 2020

For the default async hasMany the type is:

DS.PromiseManyArray<T>

but for async: false it’s:

DS.ManyArray<T>

I was thinking of creating AsyncHasMany and SyncHasMany but since async: true is default, maybe the async type should just be HasMany? Any thoughts on names?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Eloquent: Relationships
Has Many Through. The "has-many-through" relationship provides a convenient way to access distant relations via an intermediate relation. For example, let's ...
Read more >
Relationships
Vuex ORM supports several different types of relationships: ... The "has-many-through" relationship provides a convenient shortcut for accessing distant ...
Read more >
Eloquent relationships - Laravel guide - Read the Docs
Many-to-many relations are slightly more complicated than hasOne and hasMany relationships. An example of such a relationship is a user with many roles,...
Read more >
BelongsToThrough relationship needed · Issue #6161
The caveat here is that it works slightly differently than hasManyThrough and the other native relationships. Those all create a single SQL ...
Read more >
Laravel (5.7) Eloquent Relationships
The many-to-many relations are slightly more complicated than hasOne and hasMany relationships. A typical example of such a relationship is a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found