import { Switch, TextInput } from "@mantine/core";
import { IconDatabase } from "@tabler/icons-react";
import {
DEFAULT_RELATION_CASCADE,
ManyToOneRelation,
type RelationType,
RelationCascades,
RelationTypes,
} from "data/relations";
import type { ReactNode } from "react";
import { type Control, type FieldValues, type UseFormRegister, useForm } from "react-hook-form";
import { TbRefresh } from "react-icons/tb";
import { useBknd } from "ui/client/bknd";
import { Button } from "ui/components/buttons/Button";
import { MantineNumberInput } from "ui/components/form/hook-form-mantine/MantineNumberInput";
import { MantineSelect } from "ui/components/form/hook-form-mantine/MantineSelect";
import { useStepContext } from "ui/components/steps/Steps";
import { useEvent } from "ui/hooks/use-event";
import { ModalBody, ModalFooter } from "./CreateModal";
import type { TCreateModalSchema } from "./schema";
import { s, stringIdentifier } from "bknd/utils";
import { standardSchemaResolver } from "@hookform/resolvers/standard-schema";
const Relations: {
type: RelationType;
label: string;
component: (props: ComponentCtx
Many
{source} will each have one reference to {target}.
A property
{config.mappedBy || target}_id will be added to{" "}
{source} (which references {target}).
When creating
{source}, a reference to {target} is{" "}
{config.required ? "required" : "optional"}.
If a
{target} entry is deleted, the reference is{" "}
{config.on_delete ?? DEFAULT_RELATION_CASCADE}.
{config.sourceCardinality ? (
{target} should not have more than{" "}
{config.sourceCardinality} referencing entr
{config.sourceCardinality === 1 ? "y" : "ies"} to {source}.
) : null}
)}
>
);
}
function OneToOne({
register,
control,
data: {
source,
target,
config: { mappedBy, required, on_delete },
},
}: ComponentCtx) {
return (
<>
{source}.{mappedBy || target}_id {"↔"} {target}
A single entry of
{source} will have a reference to {target}
.
A property
{mappedBy || target}_id will be added to {source}{" "}
(which references {target}).
When creating
{source}, a reference to {target} is{" "}
{required ? "required" : "optional"}.
If a
{target} entry is deleted, the reference is{" "}
{on_delete ?? DEFAULT_RELATION_CASCADE}.
{source} {"→"} {table} {"←"} {target}
Many
{source} will have many {target}.
A connection table
{table} will be created to store the relations.
If an entry of
{source} or {target} is deleted, the
connection is {config.on_delete ?? DEFAULT_RELATION_CASCADE}.
{source} {"←"} {target}
{source} will have many {target}.
{target} will get additional properties referenceand{" "}
entity_idto make the (polymorphic) reference. {config.targetCardinality ? (
{source} should not have more than{" "}
{config.targetCardinality} reference
{config.targetCardinality === 1 ? "" : "s"} to {target}.
) : null}