• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DataMapper ORM v2.0 - Input requested

[eluser]Frank Wong[/eluser]
After monitoring the mysql logs, I realized that there is a discrepancy between get() and get_sql() from my previous example.

$account = new Account_dm($id);
will execute (witnessed from mysql logs)
SELECT * FROM (`books`) WHERE account_id = [id];

$account = new Account_dm($id);
$sql = $account->book_dm->get_sql();
echo $sql;
SELECT * FROM (`books`);

Objects relationships were not changed between the two tests.

get_sql() isn't meant to retrieve the SQL from every query, it is used to build subqueries. It therefore has relations disabled by default.

public function get_sql($limit = NULL, $offset = NULL, $handle_related = FALSE)

So this should work:

$account = new Account_dm($id);
$sql = $account->book_dm->get_sql(NULL, NULL, TRUE);
echo $sql;

[eluser]Frank Wong[/eluser]
Doh! Thanks for the explanation. I should have read your online instructions more clearly. It is stated there plain and simple.

I have another suggestion. I'm not sure it's possible yet : add join_field validation.
It's seems it's ignored when describing validation in one of the model's file. Also it could be in conflict with relation ship validation (if same attribut's name). Maybe something like :

public $validation = array(
  'join_name' => array(
    'rules' => array('trim'),

[eluser]Mark Price[/eluser]
I do like the fact that I don't have to define table fields in my models but it does kind of bug me that it runs a describe query on the table everytime I instantiate a DataMapper object. I think it would be great if DataMapper 2.0 cached the describe results.

The current version already does that, see http://datamapper.wanwizard.eu/pages/prodcache.html.

The idea is that you disable this in development, when your table schema is often changing, and enable it in production, so it needs to describe the tables only once.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.