Deeper model namespacing....

60 views
Skip to first unread message

rivets

unread,
Sep 9, 2021, 9:33:54 AM9/9/21
to redbeanphp
I suspect this is difficult and/or inefficient, but... I was wondering if there was an easy way to add the ability to segregate models into difference sub-namespaces (or use a search path). I have my own framework I use and have used for teaching and there are models which belong to the proper working of the framework which users should not edit (they can add functions using traits) and then there are the users' own models which are in the same directory. It would be nice to be able to separate these out so that users don't break things by accident. But probably, as I said, difficult and/or inefficient. Anyway, just a thought.

Ben Major

unread,
Sep 9, 2021, 9:47:25 AM9/9/21
to redbe...@googlegroups.com
I don't think this can be supported. It would require defining the model prefix using a wildcard or similar, but then you have the issue that a Model of the same name may exist at various levels in the namespace, for instance

App\Model\User
App\Model\Core\User

Which one should RB map to User beans? 

On Thu, 9 Sep 2021, 14:33 rivets, <lindsay....@gmail.com> wrote:
I suspect this is difficult and/or inefficient, but... I was wondering if there was an easy way to add the ability to segregate models into difference sub-namespaces (or use a search path). I have my own framework I use and have used for teaching and there are models which belong to the proper working of the framework which users should not edit (they can add functions using traits) and then there are the users' own models which are in the same directory. It would be nice to be able to separate these out so that users don't break things by accident. But probably, as I said, difficult and/or inefficient. Anyway, just a thought.

--
You received this message because you are subscribed to the Google Groups "redbeanphp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redbeanorm+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/redbeanorm/941ce6bb-3b41-4aed-880c-7afa978b6c9dn%40googlegroups.com.

rivets

unread,
Sep 9, 2021, 11:25:49 AM9/9/21
to redbeanphp

That's easy - it's like any other pathname search, you get the first hit. If you have a name clash and things break, well, you didn't read the documentation properly :-)

The Model finder is already trying a lot of different possible names already (or so the documentation says) so having a path does not seem too much of a stretch.

L.

robinou...@gmail.com

unread,
Oct 14, 2021, 10:52:07 PM10/14/21
to redbeanphp
I made a simple gist to show how you could do that by extending the BeanHelper

rivets

unread,
Oct 31, 2021, 6:51:39 AM10/31/21
to redbeanphp
Thanks for that. Will make things much cleaner for me.
Reply all
Reply to author
Forward
0 new messages