Last updated at 7:18 am UTC on 27 July 2007
Step 1. Making your domain model
First of all you need to describe your domain model. You don't need to think about input-output, data layer or something like this.
Just funny good model, that is work good in workspace.
At Sails-Test category you can find three classes: Blog, BlogPost and BlogComment. Those classes desribing a Simple Blog domain model:
- Blog consists of couple of BlogPost entries,
- Every BlogPost has a Title, Post (text itself) and couple of BlogComments,
- Every BlogComment has a Comment only (text of comment).
Step 2. Describing your objects
You need make metadescription with Magritte for every of your classes maked at Step 1.
I.e. you must create a class method descriptionField for every "external" instvar with name "field". "External" men "user interacts with it" or "I need save it in database". Every such a method must return MAElementDescription instance, describing correspondent field (let's call "external instvar" so).
NB: see Magritte documentation for detail metadesribing instructions.
You can find examples of such a description at Sails-Test category in Blog, BlogPost and BlogComment classes.
NB: focus your attention on MAToManyRelationDescription especially.
Step 3. Root element selection and Sails instance making.
Now you need select "root" class of your domain model. You will see this component representation when you start generated apllication.
If you have no such a class (for example, you have 2 or 3 "main" components), you must make artificial one with field for every "semiroot" class you have.
When your root class was finded, you need open a workspace and write code like this:
blogGen := Sails newFor: 'BlogExample'.
blogGen addModel:(SailsModel fromList:#(Blog BlogPost BlogComment)).
NB: as far as Blog is root class of BlogExample, it placed first in list. You need to place your root class first, too.
Execute this code, and Sails will generate a category Sails-Test-BlogExample with WAComponent child for every class of domain model, and will register seaside application called "BlogExample" (you will find it with seaside browser).
And this application is one, made from your model without single Seaside code.
If you are lazy.
If you are lazy and don't want waste your time on making some model and writing stuff I tell before, you can use SailsTest class. It class method named test2 describe everything needed for example blog.
You can obtain error, if you try sort MAToManyRelationDescription described fields. This error apeared, if no default values set either in initialize method or in metadescription and if your list is empty.