Hi @ewan,
I kinda came to the conclusion that creating relationships might be the best way forward for a certain use cases.
Moving away from the cars example in prior threads, what I’m trying to do with the following query is:
- Create a
User
- Create a
ChefNetwork
, using info from the newly created User
- Update the newly created
User
with the with the id of the newly created ChefNetwork
All works up to the point where I’ve marked “need some help” in the below.
Let(
{
user: Create(Collection("User"), {
data: { ...payload },
}),
cn: Create(Collection("ChefNetwork"), {
data: {
owner: Select("ref", Var("user")),
ownerId: Select(["ref", "id"], Var("user")),
ownerChefId: Select(
["data", "chefId"],
Var("user")
),
ownerChefName: Select(
["data", "chefName"],
Var("user")
),
ownerChefNickname: Select(
["data", "chefNickname"],
Var("user")
),
members: [
{
user: Select("ref", Var("user")),
chefName: Select(
["data", "chefName"],
Var("user")
),
chefNickname: Select(
["data", "chefNickname"],
Var("user")
),
isEditor: true,
},
],
},
}),
updatedUser: Update(
Ref(
Collection("User"),
Select(["ref", "id"], Var("user"))
),
{
data: {
...Select("data", Var("user")), //<== need help here
chefNetworkId: Select(
["ref", "id"],
Var("cn")
),
},
}
),
},
Var("user")
)
I obviously don’t know what I’m doing, but I’ve tried a bunch of stuff. The short of it is that I want to update the user, but to do that I need the User data.
What I wind up with on the User is the below:
raw: {
select: "data",
from: {
ref: Ref(Collection("User"), "34424219572476XXXX"),
class: Collection("User"),
collection: Collection("User"),
ts: 1664553790700000,
data: {
chefId: "bb772ca6-ef7e-4f0d-9e25-87e2629e863a",
chefName: "nancy",
chefNickname: "nancy",
chefNetwork: [
{
chefName: "nancy",
chefNickname: "nancy",
chefId: "bb772ca6-ef7e-4f0d-9e25-87e2629eXXX",
isEditor: true
}
],
chefNetworks: [],
counts: {
recipes: 0,
slurps: 0,
chefsInNetwork: 1
},
role: "normie",
secretCode: "NRZJf84te6XXXXX",
createdAt: 1664553787430,
updatedAt: 1664553787430,
lastSignedInOn: 1664553787430
}
}
},
The raw
bit makes me think I need to do something more with that ...Select
bit.
I can do a workaround, where I exclude the third entry of the query, and then run another query using the responses from the first, but I’d like to know how I can do the above without getting raw
.
Any advice would be appreciated.