0
class DataXX(Base):
__tablename__ = 'DataXX'

MyID = Column(Integer, primary_key=True, unique=True)
AnForeignID = Column(ForeignKey('xxxx.xxx'), nullable=False)

Then I am thinking to have a validate function to constrains required field AnForeignID by having the func inside of data class (below)

@validates('AnForeignID')
def validate_func(self, key, value):
# somehow this function never triggered, any help will apprecaite
BBe
  • 1
  • 2
  • Can you provide an example of what you are trying to do? `validate_func` prints out a message if I add a `print` to it, so it is being triggered. – snakecharmerb Nov 23 '20 at 08:52
  • I was going to validate required field as well as date format field but somehow it did not work until this morning I try it again and surprisingly triggered! – BBe Nov 24 '20 at 01:45
  • after I spend huge time on search on google, I thought validate does not be triggered is because of sqlalchemy version change but apparently that is not the case. This is link https://docs.sqlalchemy.org/en/13/orm/mapped_attributes.html, by saying that can you please also point out what `flush process` it is? or a quick example, will appreciate and pick your answer if you could give me some ideas. – BBe Nov 24 '20 at 01:53
  • [flushing](https://docs.sqlalchemy.org/en/13/orm/session_api.html#sqlalchemy.orm.session.Session.flush) a session send changes to the database, but does not commit them. One use case is to flush newly added objects to populate their `id` attribute, or other attributes populated by the database. – snakecharmerb Nov 24 '20 at 13:24
  • @snakecharmerb, thanks for your explanation! you are a legend! – BBe Nov 25 '20 at 00:37

0 Answers0