我有一個分支機構和員工之間的多對多關係,並希望使用思維獅身人面像(TS)來搜索current_staff成員擁有的分類帳。思維 - 獅身人面像has_many:通過關係
在Rails 3控制檯我已經試過以下
> Ledger.search 'test', :include => :staff_ids, :with => {:staff_ids => 1}
Returns []
> Ledger.search 'test', :include => :staff_id, :condition => {:staff_id => 1}
Returns ledgers which do not belong to staff member with id 1.
萊傑型號
員工型號
class Staff < ActiveRecord::Base
has_many :employees
has_many :ledgers, :through => :employees
define_index do
indexes username
indexes surname
indexes firstname
set_property :delta => true # http://freelancing-god.github.com/ts/en/deltas.html
end
end
我有以下拐點設置
inflect.uncountable %w(staff)
我試過索引,並在我的總帳模型中,每次更改索引後重建和重新啓動TS。
UPDATE1:
我非常接近。 如果我做了「耙TS:重新索引」,然後重新啓動我的導軌服務器,我的分類帳(關聯到current_staff)搜索工作正常:
@results = Ledger.search params[:search], :include =>:staff_id, :conditions =>{:staff_id => current_staff.id}
這幾乎就像我必須對我的has_many增量:通過模型,這是正確的嗎?
更新2:
我已經開始與達美航空和協會發揮各地的思維 - 獅身人面像文檔。但似乎仍然沒有工作。
以下是我已經把我的帳型號:
after_save :set_staff_delta_flag
...
private
def set_staff_delta_flag
staff.delta = true
staff.save
end
嘗試添加新的總帳時,我得到了以下錯誤:
NoMethodError (undefined method `delta=' for #<Class:0x00000001516340>):
app/models/ledger.rb:19:in `set_staff_delta_flag'
app/controllers/ledgers_controller.rb:24:in `create'