Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Automatically create/update records of child based on definition in parent or id in child #4013

Open
2 tasks done
Micnubinub opened this issue May 10, 2024 · 0 comments
Labels
feature New feature or request triage This issue is new

Comments

@Micnubinub
Copy link

Is your feature request related to a problem?

No

Describe the solution

Say we have this schema below

DEFINE TABLE IF NOT EXISTS user SCHEMAFULL;

DEFINE FIELD name ON user TYPE string;
DEFINE FIELD address ON user TYPE record<address>;


DEFINE TABLE IF NOT EXISTS address SCHEMAFULL;

DEFINE FIELD street ON address TYPE string;
DEFINE FIELD number ON address TYPE string;

At the moment if we want to create a user with a address we have to:

LET $address = (CREATE address CONTENT {
  street: "test",
  number: "123"
})[0].id

CREATE user CONTENT {
  name: "Test User",
  address: $address
}

Proposing auto create/update like so:

CREATE user CONTENT {
  name: "Test User",
  address: { # line picks up that this is address from the schema
  street: "test",
  number: "123"
}
}

CREATE|Update user CONTENT {
  name: "Test User",
  address: { 
  id: address:1, # line picks up that this is address from the id
  street: "test",
  number: "123"
}
}

Alternative methods

Just doing it manually

SurrealDB version

1.4.2

Contact Details

lindelwencube.ln@gmail.com

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Micnubinub Micnubinub added feature New feature or request triage This issue is new labels May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request triage This issue is new
Projects
None yet
Development

No branches or pull requests

1 participant