Hi!
On Sun, Nov 10, 2013 at 10:21:21PM +0100, Daniel Fetchinson <fet...@go...> wrote:
> Perhaps it is by design but I was kind of surprised to see that if I have
>
> class x(SQLObject):
> ys = RelatedJoin( 'y' )
>
> class y(SQLObject):
> ....
>
> then I'm allowed to add several times the same 'y' object to 'x' via
>
> myx = x.get( 1 )
> myy = y.get( 1 )
> x.addY( myy )
> x.addY( myy )
> x.addY( myy )
>
> Is there a keyword argument to RelatedJoin or to addY that forbids this?
There is no.
> Or I have to code this myself, i.e. check if an object is already
> added, and if yes, refuse to do it?
It is application-dependent. Please remember that RelatedJoin is
many-to-many relation using an intermediate table. I cannot contrive a
task for which there could be a few intermediate rows with the same pair
of id's but who knows what tasks people can devise.
The simplest thing you can do is to create unique indices for your
intermediate tables. The best thing you can do is to send a patch that
will create unique indices at the time of creation of RelatedJoin's.
With an option to turn the indices off.
Oleg.
--
Oleg Broytman http://phdru.name/ ph...@ph...
Programmers don't die, they just GOSUB without RETURN.
|