# Serialize array finder

**URL:** <https://www.ruby-forum.com/t/serialize-array-finder/155366>\
**Category:** Rails\
**Created:** [December 11, 2008, 3:05am UTC](https://www.ruby-forum.com/t/serialize-array-finder/155366 "2008-12-11T03:05:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![grayson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c77e96/32.png) [@grayson](https://www.ruby-forum.com/u/grayson)\
**Post date:** [December 11, 2008, 3:05am UTC](https://www.ruby-forum.com/t/serialize-array-finder/155366/1 "2008-12-11T03:05:07Z")

</div>

Hello,

Not sure if this is even possible/practical but I’d like to serialize an  
array to a string field like this and then be able to match against it.

User.find(:all, :conditions =\> [“interests in  
(?)”,current\_user.interests)

Am I better of not denormalizing? How would this be done with ordinary  
A/R relationships because I’m not looking for an exact match, I’m  
looking for any interests that the users have in common (more like a  
ranking)

GP

---

<div class="post-metadata">

**Author:** ![grayson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c77e96/32.png) [@grayson](https://www.ruby-forum.com/u/grayson)\
**Post date:** [December 11, 2008, 3:18am UTC](https://www.ruby-forum.com/t/serialize-array-finder/155366/2 "2008-12-11T03:18:04Z")

</div>

Grayson P. wrote:

> User.find(:all, :conditions =\> [“interests in  
> (?)”,current\_user.interests)

Here’s a wild guess. I hope someone else corrects it if I have lead you  
astray!

User.find(:all, :include =\> :interests,  
:conditions =\> [“interests.id IN (?)”,current\_user.interests]  
:order =\> ‘COUNT(interests.id) DESC’)

(At work we have taken to putting all raw SQL commands in ALL CAPS…)

---

<div class="post-metadata">

**Author:** ![grayson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c77e96/32.png) [@grayson](https://www.ruby-forum.com/u/grayson)\
**Post date:** [December 12, 2008, 4:06am UTC](https://www.ruby-forum.com/t/serialize-array-finder/155366/3 "2008-12-12T04:06:32Z")

</div>

Phlip wrote:

> Grayson P. wrote:
> 
> > User.find(:all, :conditions =\> [“interests in  
> > (?)”,current\_user.interests)
> 
> Here’s a wild guess. I hope someone else corrects it if I have lead you astray!

such as…

User.find(:all, :include =\> :interests,  
:conditions =\> [ “interests.id IN (?)”,  
current\_user.interests.map(&:id) ]  
:order =\> ‘COUNT(interests.id) DESC’)

and use inspect\_sql to see the query it generates!
