You could solve it by retrieving the category first, using
Category.find_by_name(@params[:categoryname]), then use @category.id.
As an added bonus, you find out if the category in question really
exists.
Regards,
Tomas
On 9/22/05, Tobias Jordans
<tobias-zjeZ61prdO8EZ6m2XrtfILNAH6kLmebB@public.gmane.org>
wrote:>
>
>
> Hello,
>
> what is the best way to say the following in .find_by_sql() or even better
> with .find()
>
>
> I have got a @params[:categoryname]
> I want to get a list of items that have belong to this category.
>
> So I want to
>
> // find
> // :all
> // where Items.category_id == (Category.id of the (Category.name >
@params))
>
> You see the problem: My params hat got the ".name" of the
category-table
> but what I need is the ".id" of this table.
>
> So eather there is a way to say it in find() in one sentence or I need to
> use a help-function that translates the .name to the .id. -- How would this
> look linke and how would I integrate it into the find()?
>
>
> Thanks!
>
> ~Tobias
>
>
> --
> Weblog: http://flyingsparks.wwwfiles.de/
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>