views:

173

answers:

1

Hi,

I have this mapper defined:

mapper(Resource, resource_table,
 properties = {'type' : relation(ResourceType,lazy = False),
  'groups' : relation(Group, secondary = model.tables['resource_group'], 
      backref = 'resources'),
  'parent' : relation(Relation, uselist=False, primaryjoin = 
      and_(relation_table.c.res_id == resource_table.c.res_id, 
      relation_table.c.end_date > datetime.now())),
  'children' : relation(Relation, primaryjoin = 
      and_(relation_table.c.parent_id == resource_table.c.res_id, 
      relation_table.c.end_date > func.now()))})

But for some reason, if I create a new row in the relation table and change the end_date of the old row in the relation to an old date, the property parent is not updated. Also if a reload the resource row, the old relation with the old date is displayed, so I am pretty sure it has to do with the date comparison in the mapper.

If I replace the end_date by a flag column string or integer and do a comparison on the flag I get the proper behaviour, but I do want to use dates.

Any help is welcome.

Thanks,

Richard Lopes

A: 

Hi,

I have actually found what was wrong. The relation is actually working. The problem was solved by setting the end_date to something like datetime.now() - 1 second, so it happens before the resource is actually refreshed by SQLAlchemy. A milliseconds issue I suppose.

Richard Lopes

Richard Lopes
Actually if the code you run takes more than 1 second this solution is not reliable enough. So up to you to put more time, or rely on a boolean flag on top of the end_date which is the safer option.
Richard Lopes