Re: filtering objects in relation

From: Craig Miskell (cmiskel..lbatross.co.nz)
Date: Mon Dec 02 2002 - 15:03:46 EST

  • Next message: martin ruff: "Re: filtering objects in relation"

    If you have a project, you could find all the tasks for that project that
    are in a given time range by using the following to create an expression,
    assuming that "Tasks" has a to-one relationship to "Projects" named "project"
    List expressionList=new ArrayList();
    expressionList.add(ExpressionFactory. binaryPathExp(
                                              Expression.LESS_THAN_EQUAL_TO,
                                              "displaybegin",
                                              currentdate));
    expressionList.add(ExpressionFactory. binaryPathExp(
                                              Expression.GREATER_THAN_EQUAL_TO,
                                              "displayend",
                                              currentdate));
    expressionList.add(ExpressionFactory. binaryPathExp(
                                              Expression.GREATER_THAN_EQUAL_TO,
                                              "project",
                                              project));
    Expression fullExpression=ExpressionFactory.joinExp(Expression.AND,
    expresionList);

    And then execute a query on Tasks with this expression.

    I hope this helps,
    Craig

    On Mon, 2 Dec 2002, martin ruff wrote:

    > Hi,
    > I've go the following two tables:
    > CREATE TABLE projects(
    > id serial NOT NULL PRIMARY KEY,
    > name varchar(100) NOT NULL UNIQUE,
    > displaybegin date,
    > displayend date,);
    >
    > and
    >
    > CREATE TABLE tasks(
    > id serial NOT NULL PRIMARY KEY,
    > fk_projectid int4 NOT NULL,
    > sortorder numeric,
    > displaybegin date,
    > displayend date,
    > FOREIGN KEY (fk_projectid) REFERENCES projects (id));
    >
    > now I want to get all projects in a time range, i.e. all projects that
    > are visible today (this works) and for every project its tasks also in a
    > given time range:
    > I defined a relation from projects to tasks (tasksArray)
    > then I have to following expression:
    > At least I think that would work :-=
    > query.addOrdering("name", true);
    > projects = theDataContext.performQuery(query);
    >
    > this returns me all projects that are visible today, works fine:
    > But how can I set the filter for the related tasks?
    > the relation taksk is defined as:
    > <db-relationship name="tasksArray" source="projects" target="tasks"
    > toDependentPK="false" toMany="true">
    > <db-attribute-pair source="ID" target="FK_projectid"/>
    > </db-relationship>
    >
    > thanks for help
    > martin
    >
    >

    Craig Miskell
    Programmer, Black Albatross, Otago University, New Zealand
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.1
    GCS d- s+:- a-->? C++++(++)$ ULXH+++$>++++ P+>++++ L++$>++++$ E--- W+++$
    N+ K? w--- !O M-- V? PS--- PE Y t++ 5 X+++ R-- tv+ b+>+++ DI++++ D+ G+ e++
    h--- r+++ y+++
    ------END GEEK CODE BLOCK------



    This archive was generated by hypermail 2.0.0 : Mon Dec 02 2002 - 15:03:56 EST