将 pg_search 限制为单个用户对象的关联
Limit pg_search to the associations of an individual User object
例如:
class User < ActiveRecord::Base
has_many :cars
end
# name :string(255)
class Car < ActiveRecord::Base
belongs_to :user
end
您将如何使用 pg_search 对只有一个 User 实例(相对于所有汽车)的汽车名称进行全文搜索?
我是 pg_search 的作者。听起来您想要做的是将 pg_search_scope 链接到一个关联上:
class User < ActiveRecord::Base
has_many :cars
end
class Car < ActiveRecord::Base
include PgSearch
belongs_to :user
pg_search_scope :search_by_name, against: :name
end
user = User.find(1)
user.cars.search_by_name("Ford")
例如:
class User < ActiveRecord::Base
has_many :cars
end
# name :string(255)
class Car < ActiveRecord::Base
belongs_to :user
end
您将如何使用 pg_search 对只有一个 User 实例(相对于所有汽车)的汽车名称进行全文搜索?
我是 pg_search 的作者。听起来您想要做的是将 pg_search_scope 链接到一个关联上:
class User < ActiveRecord::Base
has_many :cars
end
class Car < ActiveRecord::Base
include PgSearch
belongs_to :user
pg_search_scope :search_by_name, against: :name
end
user = User.find(1)
user.cars.search_by_name("Ford")