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
161 stars 47 forks source link

Belongs to many - Table can't be without an underscore #803

Closed maicol07 closed 1 year ago

maicol07 commented 1 year ago

Describe the bug In a belongs to many relationship, the table option can't be without an underscore (i.e. compositions), but it should be table1_table2. If this structure isn't present it throws an error when splitting the table name. This behaviour isn't necessary when local_foreign_key and other_foreign_key are set.

To Reproduce Steps to reproduce the behavior:

  1. Create a sample database with two tables and one "belongstomany" table
  2. Create the models for the table
  3. Use the code below for the "belongs to many" relationship
  4. Try to get the related model & see error

Expected behavior Table works with the two additional options

Screenshots or code snippets

@belongs_to_many(local_foreign_key="donut_id", other_foreign_key="", pivot_id=None, table="compositions", with_fields=["absolute_quantity"])
    def ingredients(self):
        """Get the ingredients for this donut"""
        from app.Models.Ingredient import Ingredient
        return Ingredient

Desktop (please complete the following information):

What database are you using?