On 8/29/07, Panzerlurch <[EMAIL PROTECTED]> wrote:
>
> class Entry(Entity):
>     has_field('title', Unicode(255), unique=True, required=True)
>     has_and_belongs_to_many('tags', unique=True, of_kind='Tag',
> inverse='ideas')
>
>     def __repr__(self):
>         return '<Idea "%s">' % (self.title,)
>
> class Tag(Entity):
>     has_field('tag', Unicode(50), unique=True, required=True)
>     has_and_belongs_to_many('ideas', of_kind='Idea', inverse='tags')
>
> With the above code how can i assert that Tags can only be added once
> to an Entry?
>
> t = model.Tag(tag="test")
> t1 = model.Tag(tag="secret")
>
> model.entry.append(t)
> model.entry.appen(t1)
>
> now i would expect the following to cause an error or prevent it
> somehow:
> model.entry.append(t)
> because entry has Tag t already and it makes no sense to append it
> once more.

Well, to do what you describe at the table level, we'd need to set the
columns of the secondary table as primary_key.  IMO, this should be
the default. And we could probably add the unique parameter you
describe to disable that behavior. Any thoughts? Want to try putting
together a patch for that?

Other than that, you could try playing with the new "collection_class"
argument, to have the relation behave as a set.
-- 
Gaƫtan de Menten
http://openhex.org

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLElixir" 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/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to