EzDevInfo.com

thinky

JavaScript ORM for RethinkDB

How should I do a PUT request with a JOIN in Thinky?

How would I handle a PUT request where I want to update and object, and then do a join for the provided tag ids?

I have this so far:

ctrl.put = function *(next){
  var id = this.params.id;
  var data = this.request.body;
  var tags = data.tags;

  delete data.tags;
  data.updatedAt = new Date();

  var post = yield Post.get(id).update(data);

  post.tags = tags;

  //how do I update the `Post_Tag` table here with the new tag list?
  //I also want to delete the old tag ids if they are not present in this new list

  var result = yield Post.get(post.id).getJoin({ tags: true });

  this.body = result;

  yield next;
};

Source: (StackOverflow)

Multiple 'belongsTo' relationships on thinky model

I have two models, User and Capture, where a Capture can be related to multiple users: it is owned, claimed, and processed all by three different users.

User = thinky.createModel 'User',
    id:           String
    displayName:  String
    email:        String

Capture = thinky.createModel 'Capture',
    id: String
    ownerID: String
    processedByID: String
    claimedByID: String
    created: Date
    updated: Date

Capture.belongsTo User.model, 'owner', 'ownerID', 'id'
Capture.belongsTo User.model, 'processedBy', 'processedByID', 'id'
Capture.belongsTo User.model, 'claimedBy', 'claimedByID', 'id'

The owner relationship works, but I cannot get the processedBy and claimedBy relationships to work. I'm querying with .getJoin(), and Thinky has created the secondary indexes on my tables (so it at least knows about the relationships)

What am I doing wrong? How can I get the nested objects to return in my queries?


Source: (StackOverflow)

Advertisements

Thinky/RethinkDB get certain info from joined many-to-many friend relationship

Im trying to model a many to many relationship in RethinkDB that is a friend relationship, so a user model to a user model. I've been using Thinky to help accomplish this and the relationship works, but it gets tricky really fast when i want to do more complex queries.

If my User consisted of something like this (using thinky.createModel):

Var User = thinky.createModel('User',
  {
    id: ...,
    name: ...,
    email: ...,
    location: ...,
    ...
  }

User.hasAndBelongsToMany(User, 'friends', 'id', 'id');

I want to be able to use RethinkDB's geolocation to pull the distance between friends, or even just get a friends ['id', 'name'] associated with a user.

var user = yield User.get(String(currentUser)).getJoin(
    {
      friends: {
        _apply: function(sequence) {
          return sequence.without('status').pluck('id', 'name', 'email');
        }
      }
    }).run();

This gives me an error: ReqlDriverError: toJSON. If i use .without('..') the key and value still appear but appear at the end of the array (weird...)

I want to get the distance between a user and all his/her friends.

Is there a way to accomplish this using thinky where i can just retrieve the information i want? Or if there is a way not using thinky that i can create a relation and use a plain reQl query to get what i want, how would that realtion look?

I should note im useing Koa


Source: (StackOverflow)