I am working on an app that allow posts to be made. On the front end
the user has the ability to select groups they wish to post to which
are then added to a hidden field in the form.
After the post model is filled with the form data and saved the
post_observer class then looks up the groups that the user selected
and inserts them, along with the post id into a submissions table to
tie the group and post together.
I need to be able to look up the post by group and to do that I have
group:
===
class Post
...
define_index do
...
indexes submissions.group_id, :as => "submission_group_id"
has :user_id, :created_at
has "submissions.group_id", :type => :integer, :as => "group_id"
set_property :delta => true
end
end
class PostObserver < ActiveRecord::Observer
def after_save(post)
Submission.create(...) if requires_save? # prevent a never-
ending recursive call
end
end
def Submission
after_save :set_post_delta_flag
...
def set_post_delta_flag
post.delta = true
post.save!
end
end
The method flow seems to be all good, but the tests are failing. I
have two sets of tests one that looks up my the Post.user_id attribute
which passes, it is just the tests that look up via the
submissions.group_id that fail, the Post method of which is shown
below.
def self.find_for_group(group_id, filter, page=1)
Post.search filter, :with => {:group_id => group_id}, :match_mode
=> :any, :page => page, :per_page => 10
end
So it seems that the problem is either the association is not made
properly, or things are not being rebuilt property after saving the
submission.
Thanks for any help.
--
You received this message because you are subscribed to the Google Groups
"Thinking Sphinx" 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/thinking-sphinx?hl=en.