How to use the @nozbe/watermelondb/decorators.children 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('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 Nozbe / WatermelonDB / examples / web / src / models / Post.js View on Github external
comments: { type: 'has_many', foreignKey: 'post_id' },
  }

  @field('title')
  title

  @field('subtitle')
  subtitle

  @field('body')
  body

  @relation('blogs', 'blog_id')
  blog

  @children('comments')
  comments

  @action async addComment(body) {
    return this.collections.get('comments').create(comment => {
      comment.post.set(this)
      comment.body = body
    })
  }
}
github status-im / liquid-funding / src / model / profile.js View on Github external
static associations = {
    pledges: { type: 'has_many', foreignKey: 'profile_id' },
    delegates: { type: 'has_many', foreignKey: 'profile_id' }
  }

  @field('addr') addr
  @field('event_id') eventId
  @field('canceled') canceled
  @field('commit_time') commitTime
  @field('type') type
  @field('name') name
  @field('url') url
  @field('id_profile') idProfile
  @field('block_number') blockNumber
  @children('pledges') pledges
  @children('delegates') delegates

  @action async markAsCanceled() {
    await this.update(profile => {
      profile.canceled = true
    })
  }
}
github RocketChat / Rocket.Chat.ReactNative / app / lib / database / model / Subscription.js View on Github external
@field('prid') prid;

	@field('draft_message') draftMessage;

	@date('last_thread_sync') lastThreadSync;

	@date('jitsi_timeout') jitsiTimeout;

	@field('auto_translate') autoTranslate;

	@field('auto_translate_language') autoTranslateLanguage;

	@json('last_message', sanitizer) lastMessage;

	@children('messages') messages;

	@children('threads') threads;

	@children('thread_messages') threadMessages;

	@field('hide_unread_status') hideUnreadStatus;
}
github status-im / liquid-funding / src / model / profile.js View on Github external
static table = 'profiles'
  static associations = {
    pledges: { type: 'has_many', foreignKey: 'profile_id' },
    delegates: { type: 'has_many', foreignKey: 'profile_id' }
  }

  @field('addr') addr
  @field('event_id') eventId
  @field('canceled') canceled
  @field('commit_time') commitTime
  @field('type') type
  @field('name') name
  @field('url') url
  @field('id_profile') idProfile
  @field('block_number') blockNumber
  @children('pledges') pledges
  @children('delegates') delegates

  @action async markAsCanceled() {
    await this.update(profile => {
      profile.canceled = true
    })
  }
}
github Nozbe / WatermelonDB / examples / native / src / models / Blog.js View on Github external
import { Model, Q } from '@nozbe/watermelondb'
import { field, children, lazy, action } from '@nozbe/watermelondb/decorators'

export default class Blog extends Model {
  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()
  }
}
github RocketChat / Rocket.Chat.ReactNative / app / lib / database / model / Subscription.js View on Github external
@date('last_thread_sync') lastThreadSync;

	@date('jitsi_timeout') jitsiTimeout;

	@field('auto_translate') autoTranslate;

	@field('auto_translate_language') autoTranslateLanguage;

	@json('last_message', sanitizer) lastMessage;

	@children('messages') messages;

	@children('threads') threads;

	@children('thread_messages') threadMessages;

	@field('hide_unread_status') hideUnreadStatus;
}
github RocketChat / Rocket.Chat.ReactNative / app / lib / database / model / Subscription.js View on Github external
@field('draft_message') draftMessage;

	@date('last_thread_sync') lastThreadSync;

	@date('jitsi_timeout') jitsiTimeout;

	@field('auto_translate') autoTranslate;

	@field('auto_translate_language') autoTranslateLanguage;

	@json('last_message', sanitizer) lastMessage;

	@children('messages') messages;

	@children('threads') threads;

	@children('thread_messages') threadMessages;

	@field('hide_unread_status') hideUnreadStatus;
}