MasoniteFramework / masonite4

Temporary Repository for a Masonite Rewrite for Masonite 4
14 stars 3 forks source link

craft model should follow models location configuration #214

Closed girardinsamuel closed 2 years ago

girardinsamuel commented 2 years ago

python craft model Post should create the file at location defined by models.location binding.

Problem

The issue here is that this config is defined in Masonite and the command is coming from masonite-orm.

Here are some solutions to address this issue :

Approach 1

Should we add an argument in ORMProvider when initializing MakeModelCommand ?

class ORMProvider(Provider):
    """Masonite ORM database provider to be used inside
    Masonite based projects."""

    def __init__(self, application):
        self.application = application

    def register(self):
        self.application.make("commands").add(
            MakeMigrationCommand(),
            MakeSeedCommand(),
            MakeObserverCommand(),
            MigrateCommand(),
            MigrateResetCommand(),
            MakeModelCommand(application.make("models.location")),
            MigrateStatusCommand(),
            MigrateRefreshCommand(),
            MigrateRollbackCommand(),
            SeedRunCommand(),
        ),

    def boot(self):
        pass

This would require to edit the MakeModelCommand init method to add this argument and use it when defined and when not defined use the directory option...

Approach 2

Duplicate this command inside Masonite commands and don't register the command in ORMProvider => then we can do what we want.

Approach 3

Duplicate this command inside Masonite commands and don't register the command in ORMProvider. But inherit the MakeModelCommand from masoniteorm.

girardinsamuel commented 2 years ago

@josephmancuso what's your opinion ?

Marlysson commented 2 years ago

@girardinsamuel When we use the ORM in standalone way, should have some way to define a custom folder to models too?

Asking because the masonite-orm has its own configuration file. There's a way to use one place to configure models folder in config.py ( standalone orm ) or using it inside masonite framework?

The Approach one maybe will be useful to change between this two forms to use it.

MakeModel receiving the location in constructor: from config.py or self.application.

josephmancuso commented 2 years ago

Didn't see this before.

I think this is the best solution:

Duplicate this command inside Masonite commands and don't register the command in ORMProvider => then we can do what we want.

girardinsamuel commented 2 years ago

I guess you're right, i find it always difficult to decide between duplication or not. We are often attracted by being DRY but that's not always a good thing (as we already talked about !).