Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CategoryJoins for ItemManager 2.2+
#1
CategoryJoins for ItemManager

Joins are used to combine fields into one data item from two or more categories

For very large item-objects (with bigger field values for example) and a large number of items it is sometimes advisable to split the item into two parts, and load them only at the time when they are really needed. This improves loading efficiency and saves performance for both the server and client.

Let's say we have a Members-Category with a large number of items and a number of input fields (about 12) for the address data. It's rather inefficient to spend lots of memory to fully load all the member-objects with all the address field data if we only wish to display a list of user names for example.
The one reasonable solution would be to split the members into two parts/categories: Members and Addresses with following fields.

1. Members:
[Image: im.members.fields.png?dl=1]


2. Addresses:
[Image: im.address.png?dl=1]
Member list view in admin:
[Image: im.members.list.png?dl=1]



With a very small members-objects, we can now handle very well and load the address-data by the item id only at the time when it’s really needed:

PHP Code:
$manager = new IManager();
$itemMapper $manager->getItemClass();
// ID of the Members category
$memberId 19;
// ID of the Addresses category
$addressId 5;
// Initialize all the items of category with ID 19 (Members)
$itemMapper->init($memberId);
// Let's get a member named "Banana Joe"
$joe $itemMapper->getItem('name=Banana Joe');
// Next we'll join Joe's address by linking Addresses category
$joe->join($addressId);

// Now, we can access the address fields by calling linked_fields[linked_category_id]
echo '<p>'.$joe->linked_fields[$addressId]->first_name->value ' '
    
$joe->linked_fields[$addressId]->last_name->value .'</p>'
Reply




Users browsing this thread: 1 Guest(s)