Forum: Ruby on Rails Problem with destroying multiple records........

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Af10464d988bde1b15b1a324237bad84?d=identicon&s=25 Dharmdip Rathod (dharmdip)
on 2008-12-03 14:20
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.........
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-12-03 14:46
(Received via mailing list)
On Dec 3, 1:20 pm, Dharmdip Rathod <rails-mailing-l...@andreas-s.net>
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
Af10464d988bde1b15b1a324237bad84?d=identicon&s=25 Dharmdip Rathod (dharmdip)
on 2008-12-04 05:00
Frederick Cheung wrote:
> On Dec 3, 1:20�pm, Dharmdip Rathod <rails-mailing-l...@andreas-s.net>
> 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 ...
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-12-04 10:03
(Received via mailing list)
On Dec 4, 4:00 am, Dharmdip Rathod <rails-mailing-l...@andreas-s.net>
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
Af10464d988bde1b15b1a324237bad84?d=identicon&s=25 Dharmdip Rathod (dharmdip)
on 2008-12-04 12:10
Frederick Cheung wrote:
> On Dec 4, 4:00�am, Dharmdip Rathod <rails-mailing-l...@andreas-s.net>
> 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
519d971b4225781ff523082fff137f31?d=identicon&s=25 Mahmoud Said (Guest)
on 2008-12-04 13:23
(Received via mailing list)
On Thu, Dec 4, 2008 at 6:00 AM, Dharmdip Rathod <
rails-mailing-list@andreas-s.net> 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
blog.modsaid.com
www.eSpace.com.eg
Af10464d988bde1b15b1a324237bad84?d=identicon&s=25 Dharmdip Rathod (dharmdip)
on 2008-12-04 14:01
Thx,
This topic is locked and can not be replied to.