This source details how to use proxy associations to create views and objects with the values โโof an ORM object.
However, when I add a value that matches an existing object in the database (and the specified value is unique or primary), it creates a conflicting object, so I cannot commit it.
So in my case, this is only useful as a representation, and I will need to use ORM queries to retrieve the object to be added.
Is this my only option or can I use a merge (I can only do this if it is a primary key and not a unique delimiter), or configure the constructor so that it uses an existing object in the database if it exists instead of creating a new object?
For example, from documents:
user.keywords.append('cheese inspector')
But I would like to translate something more similar: (of course, the request may fail).
keyword = session.query(Keyword).filter(Keyword.keyword == 'cheese inspector').one() user.kw.append(keyword)
OR perfect
user.kw.append(Keyword('cheese inspector')) session.merge()
I suppose this might even be a good idea, but it may be in some cases :)
Derek litz
source share