Hi,
Please explain how to create a new record into eg. customers table and getting foreign key id from another table eg. statuses so the query look like this: INSERT INTO customers (code, name, status_id) VALUES ('001', 'Customer Name', 1) but with status_id coming from the statuses table as the statuses.name is showing up when creating a new record (using Select dropdown) but getting an error message as the status_id is missing:
class CustomerResource extends Resource
{
protected function onCreated()
{
$this
->manageTable("customers")
->inSource(AutoMaker::class);
}
protected function query($query)
{
return
$query
->join("statuses","customers.status_id","=","statuses.id")
->select("customers.code","customers.name", "customers.status_id");
}
protected function fields()
{
return [
ID::create("code"),
Text::create("name"),
Number::create("status_id")
->label("Status")
->inputWidget(
Select::create()
->dataSource(function(){
return AutoMaker::table("statuses")->select("name")->distinct()->orderBy("name");
})
->fields(function(){
return [
Text::create("id")
];
})
),
];
}
}