Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Minor spelling, and make method names in text match code.

...

You will notice that the attributes have a column with a lock in it. When a lock is present, it will use the value of that attribute for UPDATE ... WHERE attribute = '' statement. This is to do optimistic locking, aka to prevent data conflict when the data object was modified by two different users. Using timestamps for optimistic locking is not a good idea because for certain RDBMS, the value can be different because of milliseconds, so remove the locks on the lastModified and creationDate attributes attribute. The final list should look like this:

...

Now, it's time to link the two entities together. A An Author can have multiple blog entries, and a BlogEntry can only have one author. To create the relationship (the join), right-click on Author and select New Relationship. On your right, select BlogEntry in the list. On your left, select to many BlogEntries, and on your right, select to one Author. Now, in BlogEntry, we need to store the primary key of the author so that we can make the join. The relationship builder allow us to add that attribute, so make sure and a new foreign key named is checked (it is checked by default). The Create Relationship pane should look like this:

...

Migrations allow you to create the tables and columns (and some types of constraint). Entity Modeler have has support to generate the code for the first migration, which is called "migration 0". To do that, open the EOModel (BlogModel EOModel in the Resources folder), right-click on the model name and select Generate Migration.

...

For this tutorial, we will implement the createAction and showAction indexAction methods. But first, we need to create a key filter. A key filter will... filter the input and the output of REST request so that you don't have to send all attributes for a blog entry. For example, we want to show the details for an author, but we don't want to show the password for the author (in real-life, the password would be encrypted)!

...

Code Block
protected ERXKeyFilter filter() {
    ERXKeyFilter personFilter = ERXKeyFilter.filterWithAttributes();
    personFilter.setAnonymousUpdateEnabled(true);

    ERXKeyFilter filter = ERXKeyFilter.filterWithAttributes();
    filter.include(BlogEntry.AUTHOR, personFilter);
    filter.setUnknownKeyIgnored(true);

    return filter;
  }

Now, let's implement the creationAction createAction method:

Code Block
public WOActionResults createAction() throws Throwable {
    BlogEntry entry = create(filter());
    editingContext().saveChanges();
    return response(entry, filter());
  }

...

Last step in the controller: implementing the showAction indexAction method. Again, the code is simple:

...

The next step to get it to work is to make BlogEntryIndexPage to implements implement the er.rest.routes.IERXRouteComponent interface.

...

Open BlogEntryShowPage.java and make sure the class extends from implements er.rest.routes.IERXRouteComponent.

...