Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Object Lookups / Assossication #875

Answered by myitcv
rawkode asked this question in Q&A
Discussion options

You must be logged in to vote

One way is to use or() with a comprehension.

package x

#Profile: {
	id:         string
	first_name: "David" | "Brian"
	last_name:  string
	// cat_id:     categories[=~".*"]
	cat_id: or([ for k, _ in categories {k}])
}

#Category: {
	id:   string
	name: string
}

profiles: [x=string]: #Profile & {
	id: x
}
categories: [x=string]: #Category & {
	id: x
}

profiles: p1: {
	first_name: "David"
	last_name:  "Bowie"
	cat_id:     "c1"
}

categories: c1: {
	name: "DevRel"
}

Note also that I've also assumed profiles and categories need to be keyed by their respective ids.

or() is really powerful because it allows you to "invert" the constraint your are looking to apply. Instead of saying "check t…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@rawkode
Comment options

Answer selected by rawkode
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants