We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should be fairly simple in the belongsTo end.
belongsTo
hasMany and belongsToMany are more complicated:
hasMany
belongsToMany
Images.relations({ owners() return this.polymorphicBelongsToMany(posts, users, pages, comments, { typeAttribute: 'owner_type', idAttribute: 'owner_id' }); }) const images = [ { id: 5, owner_type: 'posts', owner_id: 6, path: '...' }, { id: 24, owner_type: 'posts', owner_id: 8, path: '...' }, { id: 5, owner_type: 'users', owner_id: 24, path: '...' }, ] // `fetch` returns a `MultiMapper` that delegates to each of the required mappers. Images.relation('owners').of(images).fetch().then(({ posts, users }) => { // whatever });
class MultiMapper extends Chain { initialize() { this.setState({ mappers: {} }) } mappers(...mappers) { const next = keyBy(flatten(mappers), m => m.getName()) } delegateAsync(method, ...args) { const promises = mapValues(this.state.mappers, m => m[method](...args)) return Promise.props(promises); } delegate(method, ...args) { const mappers = mapValues(this.state.mappers, m => m[method](...args)) this.setState({ mappers }) } } function delegateMethods(methodNames, delegationMethod) { return transform(methodNames, (results, name) => { result[name] = function(...args) { this[delegationMethod](name, args); } }, {}); } const asyncMethods = ['fetch', 'update', 'insert', 'updateAll', 'destroyAll']; const syncMethods = ['require', 'attributes']; assign( MultMapper.prototype, delegateMethods(syncMethods, 'delegate'), delegateMethods(syncMethods, 'delegateAsync') ); export default MultiMapper;
The text was updated successfully, but these errors were encountered:
This can be supported more easily using a Proxy instance.
Proxy
Sorry, something went wrong.
No branches or pull requests
Should be fairly simple in the
belongsTo
end.hasMany
andbelongsToMany
are more complicated:The text was updated successfully, but these errors were encountered: