Ahh, found the magic.
In Rose::DB::Object::Metadata::Relationship::OneToMany I found the special 
(but buried) 'query_args' variable.  So this will do what I want:
    relationships => [
        prices => {
            type       => 'one to many',
            class      => 'Price',
            column_map => { id => 'product_id' },
            query_args => [
                or => [
                    enddate => undef,
                    enddate => { gt => 'now' },
                ],
            ],
        },
    ],


Good stuff, thanks!
-Cory

On Monday 15 January 2007 5:21 pm, Cory Bennett wrote:
> I am wondering if there is a way to represent conditional relationships. 
> In the Vendor/Product/Price tutorial example lets say I change the prices
> table to look like:
>
> CREATE TABLE prices (
>     id          SERIAL NOT NULL PRIMARY KEY,
>     product_id  INT NOT NULL REFERENCES products (id),
>     region      CHAR(2) NOT NULL DEFAULT 'US',
>     price       DECIMAL(10,2) NOT NULL DEFAULT 0.00,
>     enddate     DATETIME NULL,
>     UNIQUE(product_id, region, enddate)
> );
>
> I have added a enddate column, to represent when a price is no longer
> valid.
>
> Now in the Product I want the "prices" relationship to only fetch non
> expired prices, (ie prices where enddate is null or enddate > now).  I
> looked around the docs and code and could not find anything like this, but
> maybe i missed it.
>
> I was thinking something like:
>     relationships => [
>         prices => {
>             type       => 'one to many',
>             class      => 'Price',
>             column_map => { id => 'product_id' },
>             conditions => [
>                 or => [
>                     enddate => undef,
>                     enddate => { gt => 'now' },
>                 ],
>             ],
>         },
>     ],
>
> Is there a way to represent this relationship?  Any suggestions or
> alternatives?
>
> Thanks!
> -Cory
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share
> your opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Rose-db-object mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/rose-db-object

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Rose-db-object mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to