Welcome Guest, Not a member yet? Register   Sign In
Question about WanWizard's DataMapper
#1

[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`
WHERE `id` =  37

My code basically looks like this:
Code:
$attempt = new Login_attempt();
$attempt->where('email', $email)->get();
$attempt->delete();
$attempt->check_last_query();

It should delete all records with a specific email. What i want is:
Code:
DELETE FROM `login_attempts`
WHERE  `email` = '[email protected]'
#2

[eluser]Aken[/eluser]
http://datamapper.wanwizard.eu/pages/deleteall.html
#3

[eluser]bigbusty[/eluser]
it still returns this kinda query:

Code:
DELETE FROM `login_attempts`
WHERE `id` =  62

but it works. I somehow missed the delete all part. Sorry for this dumb post.

Thank you Aken.
#4

[eluser]Aken[/eluser]
That's because it loops through each item and deletes them individually.
#5

[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.
#6

[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)...




Theme © iAndrew 2016 - Forum software by © MyBB