Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Allow model namespace declaration on the Object Model panel #27

Closed
Perturbatio opened this issue Jun 11, 2019 · 4 comments
Closed

Allow model namespace declaration on the Object Model panel #27

Perturbatio opened this issue Jun 11, 2019 · 4 comments
Labels
Added to Trello https://trello.com/b/R11mhfdy/pipe-dream enhancement New feature or request

Comments

@Perturbatio
Copy link

It would be useful to be able to specify sub-level model namespaces via the sketch area on the Object Model panel.

I know there's a plan to add model namespacing (as per #5) however, on a larger application, I often find it useful to create deeper namespaces.

These defined namespaces could be offset from the base model directory as defined in the FileFactory modelNamespace setting

As an example, assuming you've defined a model namespace as App\Models and the build would place new models in app/Models then defining a model as Users\Contractor would create a Contractor model in the app\Models\Users directory with the namespace App\Models\Users.

The one issue with this is how you manage relationships, but that could possibly be rectified by adding the ability to specify the model used for a foreign key.

e.g. with something like contractor_id:Users\Contractor

@Perturbatio Perturbatio added the enhancement New feature or request label Jun 11, 2019
@ajthinking
Copy link
Member

Hi @Perturbatio, thank you for this idea, love it.
The Users\Contractor approach would be really cool and don't think there would be a problem with foreign keys as the title can be trimmed after the last \to get the foreign key parameter.

Another method that we discussed is something like this:
<name> : [extra args,,,,,...]
The namespace example could then be added to the end (optionally) something like this:

Contractor : App\Models\Users
name : text, nullable
email 

The last solution is possibly more all around and suitable to be provided by the default "Core package" - but your solution is better for PHP/namespaced languages. Maybe each implementation should have the posibillity to provide its own custom sketch parsing. That would be kind of cool.

Let me know what you think. Cheers!

@Perturbatio
Copy link
Author

Perturbatio commented Jun 12, 2019

If I understand your intention the Contractor in your example is a model with its namespace declared afterwards, I don't think I would have a problem with that, but if I defined the following:

Contractor: App\Models\Users
name
email

Contractor: App\Models\Companies
name

Site
name
contractor_id

How would Site know which contractor is the foreign in this case? My thought was that if I were to do:

Site
name
contractor_id : App\Models\Users\Contractor

I would be implicit about it, maybe I'm not fully understanding your explanation.

@ajthinking
Copy link
Member

Ok now I got it! Makes sense. I like that :) Started on something to facilitate this: https://github.com/pipe-dream/laravel/blob/master/src/resources/js/objectModel/SketchRow.js

@ajthinking ajthinking added the Added to Trello https://trello.com/b/R11mhfdy/pipe-dream label Jun 13, 2019
@ajthinking
Copy link
Member

Thanks @Perturbatio ! This is queued in next version, closing for now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Added to Trello https://trello.com/b/R11mhfdy/pipe-dream enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants