Welcome Guest, Not a member yet? Register   Sign In
DMZ 1.7.1 (DataMapper OverZealous Edition)

[eluser]Unknown[/eluser]
Fatal error: Uncaught exception 'Exception' with message 'Unable to call the method "join" on the class Product' in /application/libraries/datamapper.php:1030

when using:

Code:
$prod = new product;
  //Find products within last 30 days
  $prod->start_cache();
  $prod->select("p.t1, p.t2, p.t3 AS t3_name, p.t4, p.available, p.t5, c.at1 AS at1_name, c.at2");
         $prod->join("containers AS c", "p.t1_id=c.at1");
  $prod->where("p.available",'Y')->where("c.available", 'Y');
  $prod->stop_cache();
  $prod->where("DATE(p.created)>", "DATE(NOW()-INTERVAL 30 DAY)");
  $result = $prod->get();

Ive searched long and hard for a solution to this if i cant use active records join method how am i meant to perform a comparrison like this in datamapper.

i tried replacing join with:
Code:
$prod->include_related('containers', '*', TRUE);
$prod->where_related('containers', 'p.t1', 'containers_at1');

but this didn't work either

[eluser]elmystica[/eluser]
* Bump

I have three tables:
- products with an id (PK), name, etc ...
- brands with an id (PK), brand_label, etc ..
- brands_products with an id (PK), product_id, brand_id

My product -method:
Code:
<?php

class Product extends DataMapper {

var $table  = 'products';

var $has_one = array(
      'brand' => array(),
      'category' => array(),
      'gender'  => array(),
      'material' => array(),
      'shape' => array(),
      'structure' => array()
      );
      
var $has_many = array(
      
      'color' => array(),
      'list_item' => array()
      );

function __construct($id = NULL)
{
  parent::__construct($id);
}
}

My Brand Method:
Code:
<?php

class Brand extends DataMapper {

var $has_many = array('product');

function __construct($id = NULL)
{
  parent::__construct($id);
}
}


In my controller, I want to select ALL products where "brand.brand_url" is a certain brand passed along in the URL.
Code:
$product = new Product();
   $product->where_related_brand('brand_url', $this->uri->segment(3))->include_related('brand', array('id', 'brand_label', 'brand_url', 'brand_lc'), FALSE, TRUE)->get_iterated();
  

   echo $this->db->last_query() . "<br />";
  

   echo "=====================<br />";
   foreach($product as $item)
   {
    echo "<br />" . $item->brand->brand_label . ": brilnr. " .  $item->name;
    
    
   }
   echo "=====================<br />";

It gives me a query like this:
Code:
SELECT products.* FROM products LEFT OUTER JOIN brands_products brands_products ON products.id = brands_products.product_id LEFT OUTER JOIN brands brands ON brands.id = brands_products.brand_id WHERE brands.brand_url = 'gucci'

and it returns only one result ...

As this is something I will do often, what is the right way to get the correct joins within Datamapper?




Theme © iAndrew 2016 - Forum software by © MyBB