Closed elieobeid7 closed 7 years ago
My database has many foreign keys am i inserting in a wrong field? I really am not inserting arrays, unless $_POST is considered an array
select()
returns always a RowCollection
with 0 or more rows. If you need only one row, use the modifier one()
:
$cat = $db->category
->select()
->where('name = :name', [':name' => 'Nike'])
->run();
$catId = $cat->id; // array of ids. This is why it fails
$cat = $db->category
->select()
->one()
->where('name = :name', [':name' => 'Nike'])
->run();
$catId = $cat->id; // integer with the id
If you don't want to assign the relations manually, this is other option:
//Create a product
$product = $db->product->create([
'title' => $title,
'description' => $description,
'price' => $price,
]);
//Relate with the category
$product->relate($cat);
$product->relate($users);
//Save all in the database
$product->save();
Man your library is magical. I still have couple of questions thought. Can you use the relate trick to delete? I have one more question, I'll ask it tomorrow if I can't solve the issue
You can relate or unrelate data. See the docs:
https://github.com/oscarotero/simple-crud#relate-and-unrelate-data
Here's the code
https://pastebin.com/vpsq9tZ3
The error
As you can see from the code, I haven't used any array, I just followed the readme, unless I'm missing something. Regards