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

[eluser]WanWizard[/eluser]
I had nested sets working, but I bined the idea. Way to many database queries when navigating through the tree.

I now use a class that reads the entire tree into memory (one single SELECT *), and then does everything else in memory. It uses Phil Sturgeon's caching solution to cache the tree, which speeds things up even more...

[eluser]Lucas Alves[/eluser]
@WanWizard Did you use the nested set model like in http://dev.mysql.com/tech-resources/arti...-data.html ?

Using this, with 1 query you can retrieve the full tree...

[eluser]introvert[/eluser]
Hello,

I need some help.

How is it possible to write the following sql query with datamapper DMZ?

Code:
SELECT node.name, (COUNT(parent.name) - 1) AS depth
    FROM $this->table AS node,
    $this->table AS parent
WHERE node.$this->left_column BETWEEN parent.$this->left_column AND parent.$this->right_column
GROUP BY node.id
ORDER BY node.$this->left_column;

I'm particualry interested at the first 3 lines, where I select the same table AS alias.

Anyone has an idea?

The reason why I want to write this with DM is because I'm working on model extension which I'd like to make modular (without repeating the same sql code milion times accross diferent models that use Nested Sets)

Many thanks in advance!

[eluser]introvert[/eluser]
[quote author="WanWizard" date="1286060934"]I had nested sets working, but I bined the idea. Way to many database queries when navigating through the tree.

I now use a class that reads the entire tree into memory (one single SELECT *), and then does everything else in memory. It uses Phil Sturgeon's caching solution to cache the tree, which speeds things up even more...[/quote]

Could you share this code with us, perhaps?

[eluser]WanWizard[/eluser]
ExiteCMS is public, see our source browser. It's in trunk/exitecms/classes.

We're currently busy with a major rewrite, to Modular CI and Datamapper, so the version online is a bit dated, the rewrite happens in a private branch. It will be merged with the trunk when we're finished, hopefully within a few weeks.

[eluser]tomdelonge[/eluser]
Alright, so right now in my controller I get an object using dmz. Let's call it products:

$p = new Product();
$p->get();

Then I pass it to the view, and there loop through and find the reviews for each:

foreach($products as $product)
{
$product->review->get();
}

Now this is obviously a simplified version. But basically, I need to loop through the products and get the associated reviews.

I need to do all of this in my controller. How can I do this there? How can I populate each individual record in the products object?

[eluser]Unknown[/eluser]
Hi all.
Firstly, thanks for your Lib, this is a very good job Wink.

I'm looking for setting avanced relationships between more than 2 tables, but don't find a way to manage this natively with DMZ.

Consider this example.
4 tables: products / colors / sizes / types

1 product has one colors/sizes/types.

1 color has many sizes/types/products

1 size has many colors/types/products

1 type has many colors/sizes/products

In real life, there is more tables following theses relations.

Setting up relations with tables couples will be a pain, so the solution can be to create 1 global relations table like this:

table relations:
Code:
-id (auto-increment)
-product_id
-size_id
-type_id
-color_id

But i'm not sure how to configure (if it's possible) DataMapper Models, even with advanced relationship, where the table "relations" can handle more than 2 relationships.

Of course, i can manage this manually with AR and joins, but i really like the way to instantiate and manage objects.

Ideas are welcome, thanks.

[eluser]James McMurray[/eluser]
[quote author="tomdelonge" date="1286270677"]Alright, so right now in my controller I get an object using dmz. Let's call it products:

$p = new Product();
$p->get();

Then I pass it to the view, and there loop through and find the reviews for each:

foreach($products as $product)
{
$product->review->get();
}

Now this is obviously a simplified version. But basically, I need to loop through the products and get the associated reviews.

I need to do all of this in my controller. How can I do this there? How can I populate each individual record in the products object?[/quote]

$object->include_related($model, $fields = NULL, $prefix = TRUE, $instantiate = FALSE)

[eluser]introvert[/eluser]
Hello.

Is there any way to execute simple sql query without initializing new model object?

Lets say I just want to get single value from database, I dont want to waste a few lines of code and bunch of memory because of it..

Maybe something like:

Code:
$sql = "SELECT id FROM table WHERE name = 'somename'";
$id = $this->query($sql);

Any ideas?

[eluser]OverZealous[/eluser]
@introvert
Just use the built-in CodeIgniter methods. Using DMZ doesn't prevent you from using CI.

Also, instantiating a single model doesn't use up much memory. Before you try to "optimize" your application, run some tests and see if there is any benefit.




Theme © iAndrew 2016 - Forum software by © MyBB