Sunspot, Rails and Composite Primary Keys

43 views
Skip to first unread message

Peer Allan

unread,
Nov 23, 2009, 2:59:31 PM11/23/09
to ruby-sunspot
Hey all,

Has anyone had any experience using Sunspot/Sunspot Rails with an
ActiveRecord model that used a composite primary key? We are looking
like we are going to have to head down that road soon and was looking
to see if there were any lights down that way already.

Thanks

Peer

Benjamin Krause

unread,
Nov 23, 2009, 3:43:08 PM11/23/09
to ruby-s...@googlegroups.com
Peer,
I don't think Sunpot or Sunspot::Rails supports composite primary key
as of now. However it shouldn't be to hard to implement. Sunspot
expects an unique identifier to store the record in the Solr Index.
So if you have your composite primary key, you just need to build a
uniq string out of your keys.

Do you know if and how Rails supports that? I guess we can
easily use the rails way in Sunspot::Rails. I'm wondering how
Rails handles composite primary key and associations ..

Cheers
Ben

Peer Allan

unread,
Nov 23, 2009, 4:26:00 PM11/23/09
to ruby-s...@googlegroups.com
Thanks Ben, I figured as much. Just wanted to get some kind of
verification before diving into the code.

Rails does not support CPK out of the box you have to use Dr.Nic's
composite_primary_key gem to get support. Lots of legacy database
integration has forced us to love that gem

Peer
> --
>
> You received this message because you are subscribed to the Google Groups "Sunspot" group.
> To post to this group, send email to ruby-s...@googlegroups.com.
> To unsubscribe from this group, send email to ruby-sunspot...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/ruby-sunspot?hl=.
>
>
>

Mat Brown

unread,
Nov 24, 2009, 10:21:16 AM11/24/09
to ruby-s...@googlegroups.com
Hi all, just a quick note - I'd use a special Sunspot::Adapter
implementation to give you composite key support, and register that
adapter for the specific model classes that use primary keys.
Reply all
Reply to author
Forward
0 new messages