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