<p>Have you tried  </p>

<pre><code>$instance = new Calendar37Record;
$instance-&gt;deleteByPk($id);
</code></pre>

CC BY-SA 3.0
2015-06-11T15:00:55.350Z
Works! Thank you. I think I shouldn't stay up so late at night.
kr37
CC BY-SA 3.0
2015-06-11T08:43:04.050Z
2015-06-11T08:43:04.050Z
Alec Ritson
<p>I'm trying to learn how to add and delete records using Active Record.</p>

<p>This works to add:</p>

<pre><code>$instance = new Calendar37Record;
$instance-&gt;timestr = $timestr;
$success = $instance-&gt;save();
</code></pre>

<p>Given that I know the id of the record to delete, is the process to find the record and then delete it? Or can you just delete it?  I tried this, but it doesn't seem to find the record, and it complains 'The active record cannot be deleted because it is new.':</p>

<pre><code>$instance = new Calendar37Record;
$instance-&gt;findByPk($id); 
$success = $instance-&gt;delete(); 
</code></pre>

<p>Thank you for any help!</p>

<plugin-development><database>
How to find and delete with Active Record
# How to find and delete with Active Record

(Asked by: username_0 on 2015-06-11)

I'm trying to learn how to add and delete records using Active Record.
This works to add:
$instance = new Calendar37Record;
$instance->timestr = $timestr;
$success = $instance->save();

Given that I know the id of the record to delete, is the process to find the record and then delete it? Or can you just delete it?  I tried this, but it doesn't seem to find the record, and it complains 'The active record cannot be deleted because it is new.':
$instance = new Calendar37Record;
$instance->findByPk($id); 
$success = $instance->delete(); 

Thank you for any help!

**Tags:** plugin-development, database


---

## 1 answers

### Answer by username_1 on 2015-06-11. Score: 4 | Accepted answer

Have you tried  
$instance = new Calendar37Record;
$instance->deleteByPk($id);

> **Comments:**
> **username_0**: Works! Thank you. I think I shouldn't stay up so late at night.  

---

