How to use the @nozbe/watermelondb.Q.on function in @nozbe/watermelondb

To help you get started, we’ve selected a few @nozbe/watermelondb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RocketChat / Rocket.Chat.ReactNative / app / lib / database / models / Subscription.js View on Github external
@field('archived') archived

	@field('join_code_required') joinCodeRequired

	@field('notifications') notifications

	@field('broadcast') broadcast

	// // muted: { type: 'list', objectType: 'usersMuted' },
	@date('room_updated_at') roomUpdatedAt
	// // lastMessage: { type: 'messages', optional: true },

	@lazy
	roles = this.collections
		.get('roles')
		.query(Q.on('subscriptions_roles', 'subscription_id', this.id));

	@children('subscriptions_roles') subscriptions_roles

	@action deleteRoles() {
		this.subscriptions_roles.destroyAllPermanently();
	}

	@action addRole(roleId) {
		return this.collections.get('subscriptions_roles').create((sr) => {
			sr.subscriptionId = this.id;
			sr.roleId = roleId;
		});
	}
}
github RocketChat / Rocket.Chat.ReactNative / app / lib / database / models / Permission.js View on Github external
import { Model, Q } from '@nozbe/watermelondb';
import { readonly, date, lazy } from '@nozbe/watermelondb/decorators';

export default class Permission extends Model {
	static table = 'permissions'

	static associations = {
		permission_roles: { type: 'has_many', foreignKey: 'role_id' }
	}

	@readonly @date('updated_at') updatedAt

	@lazy
	roles = this.collections
		.get('roles')
		.query(Q.on('permission_roles', 'permission_id', this.id));
}
github RocketChat / Rocket.Chat.ReactNative / app / lib / database / models / Role.js View on Github external
static associations = {
		permissions_roles: { type: 'has_many', foreignKey: 'permission_id' },
		subscriptions_roles: { type: 'has_many', foreignKey: 'subscription_id' }
	}

	@field('description') description

	@lazy
	permissions = this.collections
		.get('permissions')
		.query(Q.on('permissions_roles', 'role_id', this.id));

	@lazy
	subscriptions = this.collections
		.get('subscriptions')
		.query(Q.on('subscriptions_roles', 'role_id', this.id));
}
github RocketChat / Rocket.Chat.ReactNative / app / lib / database / models / Role.js View on Github external
import { field, lazy } from '@nozbe/watermelondb/decorators';

export default class Role extends Model {
	static table = 'roles'

	static associations = {
		permissions_roles: { type: 'has_many', foreignKey: 'permission_id' },
		subscriptions_roles: { type: 'has_many', foreignKey: 'subscription_id' }
	}

	@field('description') description

	@lazy
	permissions = this.collections
		.get('permissions')
		.query(Q.on('permissions_roles', 'role_id', this.id));

	@lazy
	subscriptions = this.collections
		.get('subscriptions')
		.query(Q.on('subscriptions_roles', 'role_id', this.id));
}
github Nozbe / WatermelonDB / examples / native / src / models / Blog.js View on Github external
static table = 'blogs'

  static associations = {
    posts: { type: 'has_many', foreignKey: 'blog_id' },
  }

  @field('name')
  name

  @children('posts')
  posts

  @lazy
  nastyComments = this.collections
    .get('comments')
    .query(Q.on('posts', 'blog_id', this.id), Q.where('is_nasty', true))

  @action async moderateAll() {
    await this.nastyComments.destroyAllPermanently()
  }
}