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

[eluser]sqwk[/eluser]
This seems to work... (well almost) (Thanks a lot, TheJim—not sure whether I would have gotten to this stage alone…)

Code:
$b = new Buyer();
$b->order_by('updated', 'desc');
$b->include_related('user', NULL, TRUE, TRUE);
$b->get_paged_iterated($offset, $limit, TRUE);

foreach ($b as $row) {
    $buyer_ids[] = $row->id;
    $map[$row->id] =& $row;
}

$p = new Place();
$p->include_join_fields();
$p->where_in_related('buyer', 'id', $buyer_ids);
$p->get_iterated();

foreach ($p as $place) {
    $map[$place->join_buyer_id]->place[] = $place;
}

I cannot seem to access $place->join_buyer_id] in the final foreach loop. (The join_fields are not in the query select and not in the object.) What do I have to do in order to access the join field?

EDIT: Also the instantiation does not seem to work for $b->include_related('user', NULL, TRUE, TRUE);. I can access $row->user_username, but not $row->user->username. Not that it matters, but it would be nice to know why…

[eluser]dejavu[/eluser]
[quote author="OverZealous" date="1275414031"]@j0nxiest

You aren't using it right. The transaction hasn't failed, the validation has. You need to check the result of the $user->save() call to see if the validation failed. The validation result is also stored in $object->valid.

Transactions are only used to group a series of queries, justlike in normal SQL.[/quote]

Phil,

Could you add a note on this (validation failing and not the transaction) to the docs? I had this exact problem. The example led me to believe that the validation would cause transactions to fail/succeed, and I couldn't figure out why the trans status was NULL instead of true -or- false. This would have saved me at least a day or two of frustration.

Or you could update the example to show how to check for both validation and transaction success. I'm sure j0nxiest and I aren't the only ones to run into this by following the example.

Anyway, great work - I'm loving how DMDMZ simplifies validation and 'array' post variable handling among many other things.

Burton

[eluser]OverZealous[/eluser]
@dejavu
Sure, I can look into it.

[eluser]sqwk[/eluser]
OverZealous, could you have a look at this? (Full code in previous post) I am having trouble getting the included join field. Does include_join_field work with where_in_related?

Code:
$p = new Place();
$p->include_join_fields();
$p->where_in_related('buyer', 'id', $buyer_ids);
$p->get_iterated();

[eluser]PhireGuys[/eluser]
I'm wondering how this is useful for developing websites? I'm always interesting in learning new things, but I haven't been able to see exactly WHY someone would use this extension to codeigniter.

Care to point me in the right direction? Thanks!

[eluser]jpi[/eluser]
@Phire_SK
I find this extension useful for 3 things :
* Easily create complex SQL queries. I have never fully understood all the possibles JOIN operations in MySQL. DMZ simplify this.
* DMZ handles very well relationships between tables (one to many, many to many etc..). Foreign keys are handle at the application level, so it's not dependent on your storage engine or RDBS.
* It's a very good extension for RAD. All these get* (see documentation) methods are very powerful. It's almost magic Smile

There are two small drawbacks (IMHO) :
* If you master SQL, then at the beginning you will probably loose time in reading the (very good, very complete) documentation of DMZ. The extension is quite intuitive but still there are "a lot" of things to read and understand at the beginning. Specially for newbies (but, seen you number of posts in the forum, you are not).
* There are some overhead. I dont know how much, but ORM in general are not, i think, compatible with absolute performance. But don't forget you are not Facebook + any small server is quite powerful these days.


Anyway, I warmly recommend you give it a try.

[eluser]OverZealous[/eluser]
[quote author="squawk" date="1278710274"]OverZealous, could you have a look at this? (Full code in previous post) I am having trouble getting the included join field. Does include_join_field work with where_in_related?

Code:
$p = new Place();
$p->include_join_fields();
$p->where_in_related('buyer', 'id', $buyer_ids);
$p->get_iterated();
[/quote]

DMZ should work just fine in that exact example. Basically, calling include_join_fields sets a flag. When you next add a related object, all the fields on the join table between those objects are added to the select statement.

The method for joining a related table is shared - so there's only one place for it to occur.

Now, there is one possibility, and that is if the object was already joined previously in the query, it might not get that far in the method. I don't have easy access to the source right now.

Anyway, you can save yourself a lot of time by looking at the generated query. The troubleshooting page tells you how. Maybe you are looking for the wrong field name(s)?

[eluser]happydude[/eluser]
I know the manual dwells a lot on this, but I really some clarification here.

I have a many to many relationship between sales and products table. On the join table (sales_products), an extra field 'quantity' is added so I have: id, sale_id, product_id, quantity.

On my form, the user can select different products and enter corresponding quantity they want to order.

A sample of my form is shown below:

<select name="product[]">
<option value="1">Product 1</option>
<option value="2">Product 2</option>
</select>
&lt;input type="text" name="quantity[]" /&gt;

This form block is replicated multiple times (more of a data entry grid).

In my code, how do I save all the products coming in from the form such that the sales table and the sales_products table are appropriately populated.

Also, when querying the sales table ($sale->get()), I want the 'quantity' field in the sales_products table be a part of the results. How do I achieve this?

Thanks in advance (and sorry if the question is noobish. Big Grin)

[eluser]PhireGuys[/eluser]
[quote author="jpi" date="1278783363"]@Phire_SK
I find this extension useful for 3 things :
* Easily create complex SQL queries. I have never fully understood all the possibles JOIN operations in MySQL. DMZ simplify this.
* DMZ handles very well relationships between tables (one to many, many to many etc..). Foreign keys are handle at the application level, so it's not dependent on your storage engine or RDBS.
* It's a very good extension for RAD. All these get* (see documentation) methods are very powerful. It's almost magic Smile

There are two small drawbacks (IMHO) :
* If you master SQL, then at the beginning you will probably loose time in reading the (very good, very complete) documentation of DMZ. The extension is quite intuitive but still there are "a lot" of things to read and understand at the beginning. Specially for newbies (but, seen you number of posts in the forum, you are not).
* There are some overhead. I dont know how much, but ORM in general are not, i think, compatible with absolute performance. But don't forget you are not Facebook + any small server is quite powerful these days.


Anyway, I warmly recommend you give it a try.[/quote]

Thanks for the detailed explanation. I'll most likely try this out on my next CI build, since that one I think will have a lot of complicated MySQL calls. I've gotten used to figuring it out myself through trial and error, but this might save me a lot of time.

Thanks Smile

[eluser]introvert[/eluser]
I'm experiencing a problem with DM OZ.

It appears like it wont execute the proper sql query with the following procedure:

Group model:

Code:
class Group extends DataMapper {
    private $refresh_time = 10; //minutes

    function outdated() {
        $this->where("updated >= DATE_SUB(NOW(), INTERVAL $this->refresh_time MINUTE)");
        $this->order_by('updated', 'ASC');
        return $this;
    }
}

Call code:

Code:
$groups = new Group();
$groups->outdated();
$groups->or_where('running', true);
echo $groups->get_sql(); //this will output the proper query
$groups->get();
echo $groups->get_sql(); //will output only select part        
echo "<br/>groups : " . $groups->count() . "<br/>";

The problem is that I always get returned all group rows:
Code:
SELECT * FROM (`groups`)
instead of
Code:
SELECT * FROM (`groups`) WHERE `updated` >= DATE_SUB(NOW(), INTERVAL 10 MINUTE) OR `groups`.`running` = 1 ORDER BY `groups`.`updated` ASC

Do you have any idea what is going on?




Theme © iAndrew 2016 - Forum software by © MyBB