Enhancing an MDriven application by adding actions and establishing relationships between classes showcases the agility of the MDriven framework. This tutorial guides you through creating a new ticket action and linking users to tickets, enabling rapid development and iteration.
Adding a Create Ticket Action
To add a new action for creating tickets in your application, follow these steps:
- Open the action definitions in MDriven Designer.
- Create a new ViewModel action and name it
Add Ticket. - Set the action to be shown in the ticket search nesting.
- Configure the action to bring up the
TicketViewModel with a root object of a new ticket. - Run the application to verify that the new action appears in the ticket search window.
Once added, users can create new tickets by navigating to a window where they can enter ticket details.
Establishing a User-Ticket Relationship
To track which user creates each ticket, establish a relationship between the User and Ticket classes:
- In MDriven Designer, add a relation between
UserandTicket. - Name this relation
Creatorto indicate the user who creates the ticket. - Update the generated code and database schema to reflect this new relationship.
Modify the ticket display to show the creator's name instead of the ticket ID. Use a view hint to display this information as static and non-editable.
Updating the Database Schema
After modifying the model, evolve the database schema to accommodate the new relationship:
- Instruct the MDriven Server to evolve the database schema.
- Check the status to ensure that the foreign key has been added to the ticket table, linking to the user who created the ticket.
Assigning the Creator in OCL
Automatically assign the creator when a ticket is created using Object Constraint Language (OCL):
- Amend the
Add Ticketaction to include OCL logic. - Use a temporary variable
Tto hold the new ticket. - Assign the
Creatorattribute ofTto the current user using theoclSingletonoperator. - Return the ticket object for the ticket window.
Testing and Deployment
Test the application to ensure that the creator is correctly assigned and displayed:
- Log in and navigate to the ticket creation window.
- Create a new ticket and verify that the creator's name is automatically filled.
- Search for tickets to confirm that the new ticket appears with the correct creator information.
Finally, deploy the updated application to the MDriven Server, ensuring all changes are published and accessible.
For more insights into MDriven's capabilities, explore the Documentation:MDriven Turnkey Series and Documentation:Actions And Viewmodels, MDriven Designer.
Source
Based on the MDriven video MDriven Agile MVC - is pretty fast.
