Join

Join( source, detail )

Description

The Join function finds all index tuples from the source SetRef and uses the source's values to be retrieved from the detail index terms.

Parameters

Argument Type Definition and Requirements

source

SetRef

The source SetRef for the join operation.

detail

IndexRef or Lambda function

The IndexRef to join with the source SetRef, or the Lambda function which determines how to complete the join operation.

Returns

The SetRef for the join operation.

Examples

The index form is useful when the documents in the source_set match the terms in an index. Join returns documents from an Index (specified by detail) that match the terms from source.

client.query(
  q.Paginate(
    q.Join(
      q.Match(
        q.Index('spellbooks_by_owner'),
        q.Ref(q.Collection('characters'), '181388642114077184')
      ),
      q.Index('spells_by_spellbook'),
    )
  )
)
.then((ret) => console.log(ret))
{ data:
   [ Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections))),
     Ref(id=181388642071085568, collection=Ref(id=spells, collection=Ref(id=collections))) ] }

The Lambda form requires the Lambda function to be pure. i.e. it may not make any reads or writes.

client.query(
  q.Paginate(
    q.Join(
      q.Match(
        q.Index('spellbooks_by_owner'),
        q.Ref(q.Collection('characters'), '181388642114077184'),
      ),
      q.Lambda(
        'spellbook',
        q.Match(q.Index('spells_by_spellbook'), q.Var('spellbook')),
      )
    )
  )
)
.then((ret) => console.log(ret))
{ data:
   [ Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections))),
     Ref(id=181388642071085568, collection=Ref(id=spells, collection=Ref(id=collections))) ] }

The events view of Join contains events for joined sets as the join filtered by when the join document was live in the source set.

client.query(
  q.Paginate(
    q.Events(
      q.Join(
        q.Match(
          q.Index('spellbooks_by_owner'),
          q.Ref(q.Collection('characters'), '181388642114077184'),
        ),
        q.Index('spells_by_spellbook'),
      )
    )
  )
)
.then((ret) => console.log(ret))
{ data:
  [  { ts: 1527095186458101,
       action: 'add',
       document:
        Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections))) },
     { ts: 1527095186458101,
       action: 'add',
       document:
        Ref(id=181388642071085568, collection=Ref(id=spells, collection=Ref(id=collections))) } ] }

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve! documentation@fauna.com

Thank you for your feedback!