cancel
Showing results for 
Search instead for 
Did you mean: 

How to set up multiple custom models?

llin
Champ in-the-making
Champ in-the-making
Hi there,

I got a question about how to set up multiple custom models, possibly with same properties.

When our Alfresco grows, I need to create more than one custom content models. Some models share several properties, but mostly different. For example, Model A has "URL" property, Model B has "URL" property and they are talking about the same thing. If I give them different prefix like "a:url" and "b:url" in the model definition file. Both them will work for itself. But when I got to write "web-client-config-custom.xml" file, a problem occurred. Here are some lines in the file:


<config evaluator="string-compare" condition="Advanced Search">
      <advanced-search>
         <content-types> <!– Model A and Model B –>
            <type name="a:doc" />
            <type name="b:doc" />
         </content-types>
         <custom-properties>
          <meta-data type="a:doc" property="a:url" display-label-id="a.url" />
         <meta-data type="b:doc" property="b:url" display-label-id="b.url" />
……
         </custom-properties>
      </advanced-search>
   </config>

There are 2 URLs displayed in the "Advanced Search" extended properties. It seems very stupid, if I have more custom models and more shared properties in the future. Does anyone have any suggestion about that?  

Thanks a lot.

Ally
3 REPLIES 3

frederick
Champ in-the-making
Champ in-the-making
Hi Ally,

If several models share a number of properties, you might want to consider creating a base model and have other models extend its types and/or aspects.
For example, cmSmiley Surprisedbject defines the cm:name property. Since cm:content and cm:folder both extend from cmSmiley Surprisedbject, they both have a cm:name property too.

So if you define a c:basedoc type with c:url property, you can have a:doc and b:doc extend from it. That way, you can display urls of a:doc objects and b:doc objects with just c:url.

llin
Champ in-the-making
Champ in-the-making
Hi Frederick,

Thanks for your reply. That will be one way I will go, if nothing is better.

But what if, the same properties among multiple models are somewhat different. Does it mean I have to create more than one base model? The issue with inheritance in OOP hits me. Could I create several aspects and use them more flexibly whenever I need them? I am going to give it a shot, using "contentModel.xml" as an example.

Sorry if I didn't state clearly, just the concepts of OOP and AOP are messing up in my mind now.

Thanks for help.

Ally

frederick
Champ in-the-making
Champ in-the-making
Could I create several aspects and use them more flexibly whenever I need them?
Yes, that's exactly what they're for. My example was only derived from cmSmiley Surprisedbject. If you need the c:url property on all different kinds of objects (i.e. cross-cutting), you could put c:url in an aspect and use it anywhere you want.

Kind regards,