Question about WanWizard's DataMapper |
[eluser]bigbusty[/eluser]
Hey guys, i seem to can't get right into DataMapper. Tables with relationships seem to work fine but i have a logging table without relations and I can't handle it properly. i haven't setup any relations for this table. Inserting data works fine but deleting records creates just this query: Code: DELETE FROM `login_attempts` My code basically looks like this: Code: $attempt = new Login_attempt(); It should delete all records with a specific email. What i want is: Code: DELETE FROM `login_attempts`
[eluser]bigbusty[/eluser]
it still returns this kinda query: Code: DELETE FROM `login_attempts` but it works. I somehow missed the delete all part. Sorry for this dumb post. Thank you Aken.
[eluser]Aken[/eluser]
That's because it loops through each item and deletes them individually.
[eluser]bigbusty[/eluser]
is that because it initially has to keep the relations connected? This way it seems kind of slow to me. So far i really like datamapper. Rescues a bit of time.
[eluser]WanWizard[/eluser]
Datamapper is an ORM, not a Query Builder. It's methods operate on individual ORM objects, which is why delete() deletes the object operated on (in this case one with id 62), and delete_all() loops over the loaded object collection. If you simply want to delete a bunch of records based on some criteria, $this->db works fine. Use the best tool for the job, an ORM is never a "one-size-fits-all" solution. If you don't want to use QB calls in your code, you can also add a method to your model, and put the QB code in that method, so you can use something like $object->delete_by_email($email)... |
Welcome Guest, Not a member yet? Register Sign In |