Provide convenience types for hasMany and belongsTo relationships
See original GitHub issueWhich package(s) does this enhancement pertain to?
- @types/ember
- @types/ember__string
- @types/ember__polyfills
- @types/ember__object
- @types/ember__utils
- @types/ember__array
- @types/ember__engine
- @types/ember__debug
- @types/ember__runloop
- @types/ember__error
- @types/ember__controller
- @types/ember__component
- @types/ember__routing
- @types/ember__application
- @types/ember__test
- @types/ember__test-helpers
- @types/ember__service
- @types/ember-data
- @types/rsvp
- Other
- I don’t know
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:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
https://github.com/DefinitelyTyped/DefinitelyTyped/pull/50044
For the default async hasMany the type is:
but for
async: false
it’s:I was thinking of creating
AsyncHasMany
andSyncHasMany
but sinceasync: true
is default, maybe the async type should just beHasMany
? Any thoughts on names?