# Hello, is there a way to exclude duplicates of a field?

**URL:** <https://www.ruby-forum.com/t/hello-is-there-a-way-to-exclude-duplicates-of-a-field/107669>\
**Category:** Ferret\
**Created:** [June 25, 2007, 4:35am UTC](https://www.ruby-forum.com/t/hello-is-there-a-way-to-exclude-duplicates-of-a-field/107669 "2007-06-25T04:35:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sarah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9de053/32.png) [@sarah](https://www.ruby-forum.com/u/sarah)\
**Post date:** [June 25, 2007, 4:35am UTC](https://www.ruby-forum.com/t/hello-is-there-a-way-to-exclude-duplicates-of-a-field/107669/1 "2007-06-25T04:35:43Z")

</div>

hi,  
this is what i am trying to accomplish

Post.find\_by\_contents(“artist:#{session[:srchstring]}\*”)

this returns to me all artist with the first letter of say ‘n’ is there  
a way to not repeat valuse of the same artist?

thank you so much for the help./

---

<div class="post-metadata">

**Author:** ![sarah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9de053/32.png) [@sarah](https://www.ruby-forum.com/u/sarah)\
**Post date:** [June 25, 2007, 9:12am UTC](https://www.ruby-forum.com/t/hello-is-there-a-way-to-exclude-duplicates-of-a-field/107669/2 "2007-06-25T09:12:36Z")

</div>

On Mon, Jun 25, 2007 at 04:35:43AM +0200, sarah wrote:

> hi,  
> this is what i am trying to accomplish
> 
> Post.find\_by\_contents(“artist:#{session[:srchstring]}\*”)
> 
> this returns to me all artist with the first letter of say ‘n’ is there  
> a way to not repeat valuse of the same artist?

Not with Ferret alone. But if you combined Ferret with a custom active  
record query this should be doable. Check out find\_id\_by\_contents which  
only gets the id values from ferret, and then use these to query your  
unique artists.

find\_id\_by\_contents is used internally by find\_by\_contents, too, so you  
can have a look at the implementation to see how it is used.

Jens

–  
Jens Krämer  
webit! Gesellschaft für neue Medien mbH  
Schnorrstraße 76 | 01069 Dresden  
Telefon +49 351 46766-0 | Telefax +49 351 46766-66  
removed\_email\_address@domain.invalid | [www.webit.de](http://www.webit.de)

Amtsgericht Dresden | HRB 15422  
GF Sven Haubold, Hagen Malessa
