Hello all,

I have a question that I've searched for a bit but can't really find
anything. I might not be searching on the right things.

I have Sunspot/solr working great and now I want to start using it to
speed up Backbone.js queries. I have it currently working with straight
Rails.

==================
CONTROLLER
  def members
    @group = Group.find(params[:group_id])
    @members = @group.members.nil? ? nil : @group.members.reject {
|user| !user.active? }
    respond_with(@members.to_json
  end

MODEL (Group)
  def members
    @members ||= roles.members.collect { |role| role.user }.compact
unless roles.members.empty?
  end
==================

Basically I'm trying to figure out a way to return :members method's
results more quickly.   I know with sunspot/solr you can index methods,
but this helps with searching on a member get getting the group.  I
basically need the opposite.

What makes this more complicated is that Group has_many :users, :through
=> :roles as a polymorphic relationship.

Roles table
===================
user_id          => user's id
object_type   => object for (Group, Forum, etc)
object_id       => id of object (Group, Forum, etc)
===================

I know its complicated but it really needs to be this way.  If anyone
has any ideas I would greatly appreciate it.

Thanks

-- 
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to