Combining fields defines a way to uniquely identify an object. Useful for finding if a dataobject with given field values exists. Protects against SQL injection, and searching on unauthroised fields. Ignores fields that don't exist on the object. Adds IS NULL, or = 0 for values that are not passed. Similar to SearchContext Conjunctive query Example input: $data = array( 'FieldName' => 'data' 'AnotherField' => 32, 'NotIncludedField' => 'blah' ); $required = array( 'FieldName', 'AnotherField', 'ARequiredField' ); Example output: "FieldName" = 'data' AND "AnotherField" = 32 AND "ARequiredField" IS NULL
 public function testMissingValues()
 {
     // Tests that missing values are included in the filter as IS NULL or = 0
     // Missing value for a has_one relationship field.
     $filter = new MatchObjectFilter('Product_OrderItem', array(), array('Product'));
     $this->assertEquals($filter->getFilter(), array('("ProductID" = 0 OR "ProductID" IS NULL)'), 'missing ID value became IS NULL or = 0');
     // Missing value for a db field.
     $filter = new MatchObjectFilter('Product_OrderItem', array(), array('ProductVersion'));
     $this->assertEquals($filter->getFilter(), array('"ProductVersion" IS NULL'), 'missing DB value became IS NULL or = 0');
 }
 /**
  * Finds an existing order item.
  * @param Buyable $buyable
  * @param string $filter
  * @return the item requested, or false
  */
 public function get(Buyable $buyable, $customfilter = array())
 {
     $order = $this->current();
     if (!$buyable || !$order) {
         return false;
     }
     $filter = array('OrderID' => $order->ID);
     $itemclass = Config::inst()->get(get_class($buyable), 'order_item');
     $relationship = Config::inst()->get($itemclass, 'buyable_relationship');
     $filter[$relationship . "ID"] = $buyable->ID;
     $required = array('Order', $relationship);
     if (is_array($itemclass::config()->required_fields)) {
         $required = array_merge($required, $itemclass::config()->required_fields);
     }
     $query = new MatchObjectFilter($itemclass, array_merge($customfilter, $filter), $required);
     $item = $itemclass::get()->where($query->getFilter())->first();
     if (!$item) {
         return $this->error(_t("ShoppingCart.ITEMNOTFOUND", "Item not found."));
     }
     return $item;
 }