Nykolas Lima
Nykolas Lima

Reputation: 140

update object with SQLAlchemy

I have a method into my Repository class that receives a object that was not loaded from database but is populated with the right id and I want to update it into the database:

class Repository(object):
 def __init__(session):
  self.session = session

 def update(self, car):
  self.session.update(car)

There is no method update into session. Also if I use add method the record is not updated.

How can I update the object with SQLAlchemy?

Upvotes: 0

Views: 112

Answers (1)

Nykolas Lima
Nykolas Lima

Reputation: 140

i found it out. the right way to do it is to call session.merge(car)

Upvotes: 1

Related Questions