Mike Chai wrote:
> I'm using acts_as_taggable_on and I want to get a list of unique
> taggings. How can I do this? In a more general sense, say that I have
> a Product model with attributes name and price. I have these:
> 
> id: 1
> Name: Juice
> Price: 5
> 
> id: 2
> Name: Juice
> Price: 5
> 
> So when I do a Product.find(:all) I'll get both, but I only want one.
> How can I do this so that no matter now many "duplicates" there are,
> I'll only get one PLUS all the other UNIQUE products?

I'm confused. How does this relate to acts_as_taggable_on?

What I see here is that you have a products table that allows the 
product name to be duplicated. This sounds like a bad idea to me. It 
seems more logical to either validate that the product name is unique 
with a unique index in the database to ensure the name is always unique. 
Or identify your products by something other than the name (like maybe 
SKU Number or Item Number). Something exposed to the user that they can 
use to find the right product.

Product.find(:all) is supposed to give you both. That's what it does. If 
you must insist on doing a distinct select then you'll have to drop down 
to a lower level like...

Product.find_by_sql("SELECT DISTINCT name, price from products....")

But, again this seems like a really bad idea because you have no idea 
which one you're going to get and if you included the id in the distinct 
select then you would still get both anyway.

With all that said, I think you need to reevaluate your application's 
design.
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to