On 9/20/06, mike <[EMAIL PROTECTED]> wrote:
> i have no idea how backwards this is.  it took me over an hour just to
> track down where this was being generated.
>
> it allows you to pass a scalar ref as a condition to any custom JOINs
> using the from attribute.  i don't know if it affects anything else,
> but it makes my query (http://scsys.co.uk:8001/4102) work.

for those behind restrictive firewalls, the query desired is as follows:

SELECT
  `me`.`product_id`,
  `me`.`publisher_id`,
  `me`.`srds_classification_id`,
  `me`.`type`,
  `me`.`name`,
  `me`.`active`,
  `me`.`date_created`,
  `me`.`description`,
  `me`.`weight`,
  `me`.`universal`
FROM
  `products` `me`
  LEFT JOIN `authorizations` `authorizations` ON (
`authorizations`.`product_id` = `me`.`product_id` AND
`authorizations.active` = 1 )
WHERE
  (
      `me`.`active` = 1
    AND
      `me`.`publisher_id` = 2209
    AND
      `authorizations.authorization_id` IS NULL
  )
GROUP BY
  `me`.`product_id`

the affected part is the second condition for the JOIN.  without this
patch, the 1 is quoted as `1`, which is undesired.  with the patch,
passing the 1 as a scalar reference allows it to be passed unquoted.
the associated search construct is:

$rs->search
(
    {
        'me.publisher_id'                   => $publisher->id,
        'me.active'                         => 1,
        'authorizations.authorization_id'   => undef
    },
    {
        from        =>
        [
            { 'me', 'products' },
            [
                { 'authorizations', 'authorizations', -join_type => 'left' },
                {
                    'me.product_id'         => 'authorizations.product_id',
                    'authorizations.active' => \'1'
                }
            ]
        ],
        group_by    => [ 'me.product_id' ]
    }
);

i'm open to other suggestions; this is merely what i found to work for
me.  it merely retrieves the products that do *not* have any
associated authorizations with the active flag set to 1.

-mike

_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to