Closed Perturbatio closed 5 years ago
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!
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.
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
Thanks @Perturbatio ! This is queued in next version, closing for now.
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 https://github.com/pipe-dream/laravel/issues/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
settingAs an example, assuming you've defined a model namespace as
App\Models
and the build would place new models inapp/Models
then defining a model asUsers\Contractor
would create aContractor
model in theapp\Models\Users
directory with the namespaceApp\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