ATK Demo Walkthrough – Lesson 9

From Achievo/ATK Wiki

Jump to: navigation, search

Contents

Intro

In this lesson we deal with many-to-many relations. An example of a many-to-many relation is that between employees and projects: several employees may be working on one project, and an employee may be working on several projects.

The process to deal with a many-to-many relation in a database is called "normalization" and consists of introducing a new table. This table contains two attributes, which identify a single record from each of the two nodes that make up the many-to-many relation.

For example, in the case of the relation between employees and projects, the employeeproject table is made up of two attributes, an employee ID and a project ID. For every particular employee that is working on a particular project, there is an entry in the employeeproject table.

The Employee-Project Node

The file class.employeeproject.inc for the node that links many projects to many employees. The source for this node is not accessible from the Demo menu, so we have reproduced it here in its entirety:

<?php
  userelation("atkmanytoonerelation");
 
  class employeeproject extends atkNode
  {
    function employeeproject()
    {
      $this->atkNode("employeeproject", NF_NO_EDIT);
      $this->add(new atkManyToOneRelation("employee_id", "lesson9.employee", AF_PRIMARY));
      $this->add(new atkManyToOneRelation("project_id", "lesson9.project", AF_PRIMARY));
      $this->setTable("lesson9_employeeproject");
    }
  }
?>

The Employees Node

This node introduces the use of an atkShuttleRelation to implement a manytomany relation. The relation is represented by a 'shuttle' on screen, where the user can select one or more projects for the employee.


The Projects Node

This node introduces the use of an atkManyBoolRelation to implement a manytomany relation. The relation is represented by a series of checkboxes on screen, where the user can select one or more employees for the project.


The Module

The file module.inc contains the menu for this lesson.

Personal tools
Navigation