1

What is the best way to perform set operations using DBIx::Class? I saw that one solution would be to create a Result Source based on my query, but my conditions will be defined by the user and I don know if the best answer is to create the result source on the fly.

Basically i need to translate this type of query to DBIC where code, attr_name and value is defined by the user:

SELECT pid FROM product WHERE code = 48
INTERSECT
(
  ( SELECT pid FROM attr WHERE attr_name = 'color' AND value = 'blue'
    INTERSECT
    SELECT pid FROM attr WHERE attr_name = 'size' AND value = 'big'
  )
  UNION
  ( SELECT pid FROM attr WHERE attr_name = 'color' AND value = 'green'
    INTERSECT
    SELECT pid FROM attr WHERE attr_name = 'size' AND value = 'small'
  )
)
nsbm
  • 5,842
  • 6
  • 30
  • 45
  • When you say defined by the user do you mean there may be more or less than the 9 placeholders above? – cubabit Aug 10 '11 at 12:59
  • Yes, exactly. The user can define many filters using pairs of (attr_name, value) and intersections and unions. – nsbm Aug 10 '11 at 13:57

1 Answers1

2

Could DBIx::Class::Helper::ResultSet::SetOperations be what you need?

titanofold
  • 2,852
  • 1
  • 15
  • 21
cubabit
  • 2,527
  • 3
  • 21
  • 34
  • Actually I cannot use this DBIC Helper because Im on a project with several groups and we all use the same database schema and the same DBIC layer. And to use this module I will have to change my Resultset Base Class and I need to keep compatibility with the other groups. – nsbm Aug 11 '11 at 16:25