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

[eluser]eXpi[/eluser]
[quote author="OverZealous" date="1284839878"]@eXpi

There's no built-in functionality for this. Solving this depends on how the items are related. If it's a one-to-many relationsip and you are using ITFKs, then you can simply query against the relationship column. Otherwise, you'll need to hand-build the query.[/quote]

Thanks for the answer! Here's the custom query that solved the problem for me, in case anyone is interested or willing to submit better solution:
Code:
$prodother = new Product();        
    $prodother->query("" .
        "select * from products where not exists ( " .
        "select * from categories_products where " .
        "categories_products.product_id = products.id " .
        "and categories_products.category_id = $id )");

[eluser]cube1893[/eluser]
Hi,

I'm wondering if I can add parenthesis to the datamapper where , or_where and where_related functions in order to build the following query:

Code:
Select all 50 year old customers who have status 1 or 2.
SELECT * FROM customers WHERE age = 50 AND (status = 1 OR status = 2)

Because this code

Code:
$c = new Customer();
$c->where('age', 5);
$c->where('status', 1);
$c->or_where('status', 2);
$c->get();

will result in this query:

Code:
Select all 50 year old customers who have status 1 or all customer who have status 2.
SELECT * FROM customers WHERE age = 5 AND status = 1 OR status = 2

That's why I need the parenthesis! Do I have to use the DMZ query() to solve this or is there another way?

[eluser]OverZealous[/eluser]
@cube1893
Please see the manual.

[eluser]cube1893[/eluser]
Dude, you made my day! I'm consumng the manual quite often but I didn't realize that "group" is the term I'm looking for.
Thank you.

[eluser]Lucas Alves[/eluser]
Hi,

I have a doubt. How could I do this: TIME_TO_SEC(TIMEDIFF(finished, created)) ?

This works fine:
Code:
$o->select_func('TIMEDIFF','@finished','@created','time_difference');

But, I can't do it with a function inside a function.

I searched in the manual but I only found "one function" examples.

Thanks.

[eluser]jpi[/eluser]
UP Smile

I am far from using "function inside function" in MySQL. I am just curious to know whether it is possible in DMZ Smile

[eluser]matthewwithanm[/eluser]
Could somebody tell me what I'm doing wrong with include_related? I have these models:

Code:
class User extends Datamapper {
    public $has_one = array('group');
}

class Group extends Datamapper {
    public $has_many = array('user');
}

My db has two tables: users (with id, name and group_id fields) and groups (with id and name fields).

I have the following code in a controller taken almost verbatim from the docs:

Code:
$users = new User();
$users->include_related('group', array('id', 'name'), TRUE, TRUE)->get();
foreach ($users as $user)
{
    echo "<li>{$user->group->name}</li>";
    echo "<li>{$user->group_name}</li>";
}

The output is:

Code:
* The Group's Name
*

In other words, I can't access the property through the instantiated related object. Am I doing something wrong? Or is there a bug in the newest DataMapper?

[eluser]Lucas Alves[/eluser]
@matthewwithanm can you access through $user->group_name ?

[eluser]WanWizard[/eluser]
Include_related does exactly that, it includes the related fields, it doesn't instantiate objects.

[eluser]James McMurray[/eluser]
[quote author="WanWizard" date="1285800388"]Include_related does exactly that, it includes the related fields, it doesn't instantiate objects.[/quote]

According to the documentation, when he set the last parameter to TRUE in the call to include_related() it should have instantiated the related objects automatically.

I had a heaping mess of trouble with include related as well, and eventually went with another method, though I'm pretty sure there's some simple thing I missed that would have made it much easier. That's what happened with all of my other questions. Smile




Theme © iAndrew 2016 - Forum software by © MyBB