-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add BaseBuilder::deleteBatch() #6734
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
Conversation
38f6d32
to
8403760
Compare
One thing that this PR does is allow to delete a set of data with a composite primary key. $orderLineItems = [
['order' => 48321, 'line' => 3, 'product' => '500G Hardrive', 'qty' => 1, 'price' => 149.99],
['order' => 48321, 'line' => 5, 'product' => '32G DDR4 Ram', 'qty' => 2, 'price' => 284.75],
['order' => 48321, 'line' => 6, 'product' => 'English Keyboard', 'qty' => 1, 'price' => 49.87],
];
$this->db->table('order_line_items')
->setData($orderLineItems)
->onConstraint('order, line')
->deleteBatch(); |
45d01b2
to
6e3e6b4
Compare
If we can merge #6689 then I will also add delete from query. |
Or we could merge this first and add delete from query to #6689 |
This is just an English question. CodeIgniter4/system/Database/BaseBuilder.php Lines 1971 to 1974 in 0fff1c9
|
Please add a note in the user guide. |
I spelled it wrong, it should be pseudo. I mean that when you have: (
SELECT 1 id, 'Jason' name UNION ALL
SELECT 2 id, 'Todd' name
) AS pseudo_table You are creating a table in SQL. This snippet of code can be dropped anywhere a table name can go. By itself though it is not a valid query. You can query this pseudo table just like any other table.. you can join this table like any other table. Its a pseudo table because the table as aliased doesn't really exist as a table in the schema but is generated on the fly. SELECT pseudo_table.name
FROM
(
SELECT 1 id, 'Jason' name UNION ALL
SELECT 2 id, 'Todd' name
) AS pseudo_table
WHERE pseudo_table.id = 1
# Here is with a real table
SELECT pseudo_table.name
FROM pseudo_table
WHERE pseudo_table.id = 1 pseudo-
|
Ah, it's pronounced the same. |
31e6998
to
7a92ae2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to ask you to check one thing, but other than that, I think this is ready.
This PR is pretty strait forward I think. This mostly falls in the footprint of the other *Batch() methods. I don't think there are any major controversies to discuss here are there? I know for me this would be very helpful as most of my database has composite primary keys. I think the order line item is a good example of where this is useful. @kenjis what do you think? Any chance of getting this committed before 4.3? |
I would like to include this in v4.3.0. |
Great news! Let me know how I can help. |
I have made some minor comments, but overall it looks good. Also, the base is a bit old, so please rebase. |
Use key value pair for mapping source to destination.
escape was fixed in another PR. Needed to remove hack.
No longer needed because setAlias() now tracks the alias and prevents prefix from being added.
88c2f64
to
9fffd23
Compare
Needs #6741The *Batch() saga continues..
This adds deleteBatch() to Builder. This allows using a set of data to selectively delete items from a table.
You can also use where() for additional conditions except with SQLite.
Checklist: