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

#21
[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.

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

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

Objects relationships were not changed between the two tests.

#22
[eluser]WanWizard[/eluser]
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.

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

So this should work:

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

#23
[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.

#24
[eluser]Spir[/eluser]
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 :

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

#25
[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.

#26
[eluser]WanWizard[/eluser]
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.