# Problem with destroying multiple records

**URL:** <https://www.ruby-forum.com/t/problem-with-destroying-multiple-records/154745>\
**Category:** Rails\
**Created:** [December 3, 2008, 2:20pm UTC](https://www.ruby-forum.com/t/problem-with-destroying-multiple-records/154745 "2008-12-03T14:20:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dharmdip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e274bd/32.png) [@dharmdip](https://www.ruby-forum.com/u/dharmdip)\
**Post date:** [December 3, 2008, 2:20pm UTC](https://www.ruby-forum.com/t/problem-with-destroying-multiple-records/154745/1 "2008-12-03T14:20:14Z")

</div>

Hi ,

i am facing problem while i am writing code  
e.g.

People.find\_by\_id(params[:id])  
comment.find\_by\_id(params[:id])

when this execute it will delete only one record from the database which  
it get first. It will keep other records same.Is there any alternative  
to delete all records based this method.

i tried with people=People.find(:all, :conditions=\>[“id=?”,params[:id]])  
but result is same.

please help…

---

<div class="post-metadata">

**Author:** ![dharmdip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e274bd/32.png) [@dharmdip](https://www.ruby-forum.com/u/dharmdip)\
**Post date:** [December 3, 2008, 2:46pm UTC](https://www.ruby-forum.com/t/problem-with-destroying-multiple-records/154745/2 "2008-12-03T14:46:50Z")

</div>

On Dec 3, 1:20 pm, Dharmdip R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> to delete all records based this method.
> 
> i tried with people=People.find(:all, :conditions=\>[“id=?”,params[:id]])  
> but result is same.

This doesn’t really make sense to me. There is only one record for a  
given value of the id column (or rather rails assumes that id is your  
primary key) so what were you expecting?

Fred

---

<div class="post-metadata">

**Author:** ![dharmdip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e274bd/32.png) [@dharmdip](https://www.ruby-forum.com/u/dharmdip)\
**Post date:** [December 4, 2008, 5:00am UTC](https://www.ruby-forum.com/t/problem-with-destroying-multiple-records/154745/3 "2008-12-04T05:00:17Z")

</div>

Frederick C. wrote:

> On Dec 3, 1:20ï¿½pm, Dharmdip R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > to delete all records based this method.
> > 
> > i tried with people=People.find(:all, :conditions=\>[“id=?”,params[:id]])  
> > but result is same.
> 
> This doesn’t really make sense to me. There is only one record for a  
> given value of the id column (or rather rails assumes that id is your  
> primary key) so what were you expecting?
> 
> Fred

I want all records base on query which i have written in  
people=People.find(:all, :conditions=\>[“id=?”,params[:id]])  
i am getting only one record not all records …

---

<div class="post-metadata">

**Author:** ![dharmdip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e274bd/32.png) [@dharmdip](https://www.ruby-forum.com/u/dharmdip)\
**Post date:** [December 4, 2008, 12:10pm UTC](https://www.ruby-forum.com/t/problem-with-destroying-multiple-records/154745/4 "2008-12-04T12:10:00Z")

</div>

Frederick C. wrote:

> On Dec 4, 4:00ï¿½am, Dharmdip R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > > primary key) so what were you expecting?
> > 
> > > Fred
> > 
> > I want all records base on query which i have written in  
> > people=People.find(:all, :conditions=\>[“id=?”,params[:id]])  
> > i am getting only one record not all records …
> 
> There is only ever one such record because the primary key is unique  
> (by definition).
> 
> Fred

k

---

<div class="post-metadata">

**Author:** ![dharmdip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e274bd/32.png) [@dharmdip](https://www.ruby-forum.com/u/dharmdip)\
**Post date:** [December 4, 2008, 10:03am UTC](https://www.ruby-forum.com/t/problem-with-destroying-multiple-records/154745/5 "2008-12-04T10:03:43Z")

</div>

On Dec 4, 4:00 am, Dharmdip R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > primary key) so what were you expecting?
> 
> > Fred
> 
> I want all records base on query which i have written in  
> people=People.find(:all, :conditions=\>[“id=?”,params[:id]])  
> i am getting only one record not all records …

There is only ever one such record because the primary key is unique  
(by definition).

Fred

---

<div class="post-metadata">

**Author:** ![dharmdip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e274bd/32.png) [@dharmdip](https://www.ruby-forum.com/u/dharmdip)\
**Post date:** [December 4, 2008, 2:01pm UTC](https://www.ruby-forum.com/t/problem-with-destroying-multiple-records/154745/6 "2008-12-04T14:01:05Z")

</div>

Thx,

---

<div class="post-metadata">

**Author:** ![dharmdip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e274bd/32.png) [@dharmdip](https://www.ruby-forum.com/u/dharmdip)\
**Post date:** [December 4, 2008, 1:23pm UTC](https://www.ruby-forum.com/t/problem-with-destroying-multiple-records/154745/7 "2008-12-04T13:23:26Z")

</div>

On Thu, Dec 4, 2008 at 6:00 AM, Dharmdip R. \<  
removed\_email\_address@domain.invalid\> wrote:

> > given value of the id column (or rather rails assumes that id is your  
> > primary key) so what were you expecting?
> > 
> > Fred
> 
> I want all records base on query which i have written in  
> people=People.find(:all, :conditions=\>[“id=?”,params[:id]])  
> i am getting only one record not all records …

I think this is not the real query you are having. you just chose a  
wrong  
example

Assuming what u really want is to semulate  
people=People.find(:all,  
:conditions=\>[“country\_id=?”,params[:country\_id]])  
where country\_id is a foreign key to something else

People.find\_by\_country\_id(params[:country\_id]) will retrieve only the  
first record matching the condition.

you should use People.find\_all\_by\_country\_id(params[:country\_id]) to  
get  
all matching results.

hope it helps

–  
Mahmoud Said  
Software Developer

> **[Thoughts](http://blog.modsaid.com)**

www.eSpace.com.eg
