Hello,
Paul Johnston a écrit :
> Hi,
>
> I'm trying to create a relation like this
>
> Testing [1] -> [many] Target (where target.is_testtgt==0)
>
> i.e. I want to map only to Target rows that match the where condition.
>
> Now, this is easy enough using assign_mapper:
>
> assign_mapper(ctx, Testing, testing, properties={ 'targets':
> relation(Target,
> primaryjoin=((target.c.testingid==testing.c.id) &
> (target.c.is_testtgt != 1))) } )
>
> However, I'm using ActiveMapper. I can't do the same, as the relation
> needs to use Testing.c.id <http://Testing.c.id>, and at that point
> Testing isn't defined, causing this to error:
>
> target = one_to_many('Target', colname='testingid',
> backref='testing', primary_join=(( Testing.c.id==Target.c.testingid) &
> (Target.c.is_testtgt != 1)))
>
> So, I thought I'd add the relation later on. Again, this is easy with
> assign_mapper:
>
> mp.properties['target'] = relation(Target,
> primaryjoin=((Target.c.testingid == Testing.c.id
> <http://Testing.c.id>) & (Target.c.is_testtgt != 1)) )
>
> And that works fine. I thought to do the equivalent with ActiveMapper:
>
> class_mapper(Testing).properties = {'target': relation(Target,
> primaryjoin=((Target.c.testingid == Testing.c.id
> <http://Testing.c.id>) & (Target.c.is_testtgt != 1)) ) }
>
Have you tried :
Testing.mapper.add_property('target', relation(Target, primary....))
(of course after having defined the Testing and Target classes...)
> But then "Testing.get(1234).targets" gives an AttributeError.
>
> So, is there any way to achieve this using ActiveMapper? Any help
> appreciated.
>
> Paul
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---