MasoniteFramework / orm

Masonite ORM is a beautiful Python ORM. It's also a nearly drop in replacement of the Orator ORM
https://orm.masoniteproject.com
MIT License
165 stars 48 forks source link

Fix record creation in model observer #786

Closed federicoparroni closed 2 years ago

federicoparroni commented 2 years ago

That issue can be solved by inverting the attach logic:

class Restore(Model):
    # ....
    def createFallback(self):
        backup = Backup.create({
            'website_id': self.backup.website_id,
            'name': 'Automatic backup before restore',
        })
        # self.attach('fallback', backup)  # changed this
        backup.attach('restore', self)     # to this
        self.save()