Cannot update a model instance in a many to many relation
See original GitHub issueDescribe the bug Updating a model instance involved in a many to many relation throws the following exception:
'(1054, "Unknown column \'mytable.pivot\' in \'field list\'")'
To Reproduce
- Declare two models connected in a many to many relation:
class Ssl(Model): __table__ = 'ssls' @belongs_to_many('ssl_id', 'app_id', 'id', 'id', table='ssl_app') def apps(self): from .app import App return App class App(Model): __table__ = 'apps' @belongs_to_many('app_id', 'ssl_id', 'id', 'id', table='ssl_app') def ssls(self): from .ssl import Ssl return Ssl - Update an entity:
app = App.find(2) for ssl in app.ssls: # custom logic to decide if update or not ssl.my_column = my_value ssl.save() # Exception!
Expected behavior Model instance should be updated without issues.
Screenshots or code snippets The generated query is:
"UPDATE `ssls` SET `ssls`.`pivot` = '?', `ssls`.`my_column` = '?' WHERE `ssls`.`id` = '?'"
with the following param bindings:
0:<masoniteorm.models.Pivot.Pivot object at 0x7f656007ebf0>
1:None
2:54
Desktop (please complete the following information):
- OS: Ubuntu
- Version: 21.04
What database are you using?
- Type: MySQL
- Version: 14.14 Distrib 5.7.30, for Linux (x86_64)
- Masonite ORM 2.6.1
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:14 (13 by maintainers)
Top Results From Across the Web
How to update manytomany field in Django? - Stack Overflow
In SQL is really easy to do. If id of "George" = 3 and id of "Georfe" = 7 and the relation table...
Read more >Many-to-many relationships - Django documentation
To define a many-to-many relationship, use ManyToManyField . In this example, an Article can be published in multiple Publication objects, and a Publication ......
Read more >Making queries — Django 4.1.4 documentation
While it can be customized , by default you refer to a “reverse” relationship in a lookup using the lowercase name of the...
Read more >The right way to use a ManyToManyField in Django
To maintain a many-to-many relationship between two tables in a database, the only way is to have a third table which has references...
Read more >Eloquent: Relationships - The PHP Framework For Web Artisans
Inserting & Updating Related Models. The save Method; The create Method; Belongs To Relationships; Many To Many Relationships. Touching Parent Timestamps ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Ok ill review it when you do 😃
@federicoparroni Can this one be closed now? #649 has been merged.