Voyage: default class to collection mapping

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Voyage: default class to collection mapping

Torsten Bergmann
Voyage by default provides this:

  voyageCollectionName
        "This method can be overridden with a more meaningful collection name"
        ^ ((self persistentClass name first: 3) allSatisfy: #isUppercase)
                ifTrue: [ (self persistentClass name allButFirst: 2) asLegalSelector ]
                ifFalse: [ self persistentClass name asLegalSelector ]


So a class name like Association will end up in a mongo collection
like "association".

But a class name with a prefix like "PDFLetter" will end up in a mongo
collection name like "fLetter".

Is there a reason for this specific default behavior and not having the
class name (by default) as the collection name in mongo? I know I can override
the method - but I wonder why it is treated specially also leading to potential
conflicts:

   PDFLetter voyageCollectionName  -> #fLetter
   FLetter voyageCollectionName    -> #fLetter

Thx
T.


Reply | Threaded
Open this post in threaded view
|

Re: Voyage: default class to collection mapping

Gastón Dall' Oglio
Hi Torsten.

May not be the case, but I've seen do that elsewhere (in Pier I think) and the reason is simply remove (sanitize) the namespace of the class (the first two letters in uppercase).

Best.


2014-07-09 17:12 GMT-03:00 Torsten Bergmann <[hidden email]>:
Voyage by default provides this:

  voyageCollectionName
        "This method can be overridden with a more meaningful collection name"
        ^ ((self persistentClass name first: 3) allSatisfy: #isUppercase)
                ifTrue: [ (self persistentClass name allButFirst: 2) asLegalSelector ]
                ifFalse: [ self persistentClass name asLegalSelector ]


So a class name like Association will end up in a mongo collection
like "association".

But a class name with a prefix like "PDFLetter" will end up in a mongo
collection name like "fLetter".

Is there a reason for this specific default behavior and not having the
class name (by default) as the collection name in mongo? I know I can override
the method - but I wonder why it is treated specially also leading to potential
conflicts:

   PDFLetter voyageCollectionName  -> #fLetter
   FLetter voyageCollectionName    -> #fLetter

Thx
T.



Reply | Threaded
Open this post in threaded view
|

Re: Voyage: default class to collection mapping

EstebanLM
you also can change the collection name without overriding the method, you just need to declare a <mongoContainer> method: 


MyClass class>>#mongoContainer 
<mongoContainer>

^ VOMongoContainer new 
collectionName: ‘myname’;
yourself

the purpose of the method is, as Gaston says, just to sanitize the name (and yes, I just copied the pier implementation).

cheers, 
Esteban


On 11 Jul 2014, at 15:43, Gastón Dall' Oglio <[hidden email]> wrote:

Hi Torsten.

May not be the case, but I've seen do that elsewhere (in Pier I think) and the reason is simply remove (sanitize) the namespace of the class (the first two letters in uppercase).

Best.


2014-07-09 17:12 GMT-03:00 Torsten Bergmann <[hidden email]>:
Voyage by default provides this:

  voyageCollectionName
        "This method can be overridden with a more meaningful collection name"
        ^ ((self persistentClass name first: 3) allSatisfy: #isUppercase)
                ifTrue: [ (self persistentClass name allButFirst: 2) asLegalSelector ]
                ifFalse: [ self persistentClass name asLegalSelector ]


So a class name like Association will end up in a mongo collection
like "association".

But a class name with a prefix like "PDFLetter" will end up in a mongo
collection name like "fLetter".

Is there a reason for this specific default behavior and not having the
class name (by default) as the collection name in mongo? I know I can override
the method - but I wonder why it is treated specially also leading to potential
conflicts:

   PDFLetter voyageCollectionName  -> #fLetter
   FLetter voyageCollectionName    -> #fLetter

Thx
T.