Cześć wszystkim Zwykle wrzucam problemy na stackoverflow, ale niestety jest tam tyle postów, że nie zawsze znajdzie sie osoba, która pomoże.
Pozwoliłem sobie przekleić informacje po angielsku. Generalnie chodzi mi o to, żeby znależć 2 oddzielne CustomFieldsRelationship w jednym zapytaniu i zwrócić ich wspólne posty z którymi mają relacje.
Moja oryginalna wiadomość ze stacka:
I use Camaleon CMS and I try to create filters based on additional “custom fields”. I think to answer this question you dont have to know this cms.
I want to find common part of 2 queries or make it in one query(that would be the best)
I have
@posts = Cama::PostType.first.posts.includes(:custom_field_values)
@param_localization = "Paris"
@param_type_localization = "House"
@posts_one = @posts.merge(CamaleonCms::CustomFieldsRelationship.
where("cama_custom_fields_relationships.custom_field_slug = ? AND
LOWER(cama_custom_fields_relationships.value) LIKE ?", "localization",
"%#{@param_localization}%"))
puts @posts_one.count => 2
@posts_two = @posts.merge(CamaleonCms::CustomFieldsRelationship.where(custom_field_slug:
"type-localization", value: @param_type_localization))
puts @posts_two.count => 2
Question is how can I merge it together or make it one query ? When I made it in one where clause
it returns me 0 results since I need to find 2 diffrent custom fields relationships that has diffrent values and slugs but it have relations to posts throught :custom_fields_values, so I have to make 2 queries I guess(like I did). First I find customFieldRelationship with slug = localization
and second with slug = type_localization
and then I need to find common part
I tried to @result = @posts_one.merge(@posts_two)
but I got no result then. I thought it will return me “common part” of association which means 2 results
How can I combine it to find me posts that fullfil both queries ?
Let me know if I explained my problem not well enought.