CodeIgniter Forums
DMZ 1.7.1 (DataMapper OverZealous Edition) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: DMZ 1.7.1 (DataMapper OverZealous Edition) (/showthread.php?tid=28550)



DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 08-01-2010

[eluser]introvert[/eluser]
Hello.

I have a question regarding DMZ htmlform extension, which I know its not supported anymore but I'm stuck with it.

I want to display a model form which has a related model and it's field is displayed normally with the listing of all items.

Form name:
some field
some related model field (select box with items: related 1, related 2, etc.)

I want to add option for "None" => 0 selection to it and I have no idea which would be the proper/best way to do this.

I know about defining function get_htmlform_list in the model class but this wont return any array of data which I could manipulate to add the desired option/value.

Is there any way to do this with the least effort/changes?

Many thanks in advance.


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 08-02-2010

[eluser]dejavu[/eluser]
Updated the select() method to better match the ActiveRecord version. ActiveRecord can accept an array or a string.

Code:
public function select($select = '*', $escape = NULL)
    {
        if ($escape !== FALSE) {
            if (!is_array($select)) {
                $select = $this->add_table_name($select);
            } else {
                $updated = array();
                foreach ($select as $sel) {
                    $updated = $this->add_table_name($sel);
                }
                $select = $updated;
            }
        }
        get_class_methods($this->db);
        $this->db->select($select, $escape);
        
        // For method chaining
        return $this;
    }

I'm not exactly clear on what add_table_name is supposed to do. So although it's working perfectly for me, I can't say if it's the correct solution. If select really has to be a string, I had a second version that basically added if(is_array($select)) $select = implode(',',$select);


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 08-02-2010

[eluser]Unknown[/eluser]
I have a table with a single primary integer key, but it is named "my_id", not "id" (for example).

Can DataMapper be extended to support a primary integer key for a table which is NOT named "id"? It is limited for use with existing tables that do not have a field named "id" and cannot be changed because they are already core tables which are supporting an existing codebase.

I have looked at the source code and see a lot of code that depends on the "id" property, especially in the relationship/join portions (where "id" is often hardcoded in the queries). However, if we could have an override (kind of like the $table property, perhaps called $id_name or something like that), which could be set on the model object, and used whenever referring to the primary ID key internally in the DMZ code, that would help a lot.

Phil, I really like DMZ and thank you for maintaining and enhancing it. If you have any suggestions or thoughts about how this scenario can be handled, they are greatly appreciated!


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 08-02-2010

[eluser]matyhaty[/eluser]
Hi All
\Im wondering if anyone can help me, with what must be a simple issue!!

I have a couple of tables...

surveys
surveytypes

and they have a relationship, which get the table name:
surveys_surveytypes

This is all working well, and can save nicely.

In the surveytypes tables is a very simple structure. Here are some made up entries:

id = 1
title = 'type1'

id = 2
title = 'Another name'

All I want to be able to do is query the surveys table and get the surveytypes.title in the results

Currently I have:
Code:
$st = new Survey();
        $st->get();
        $this->data['surveys'] = $st;

which gets all the Survey information just fine. How do I get the surveytypes.title included in this?

Many Thanks

Matt


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 08-03-2010

[eluser]dejavu[/eluser]
[quote author="matyhaty" date="1280805552"]Hi All
\Im wondering if anyone can help me, with what must be a simple issue!!

which gets all the Survey information just fine. How do I get the surveytypes.title included in this?

Many Thanks

Matt[/quote]

Read the manual.

include_related() is explained at http://www.overzealous.com/dmz/pages/getadvanced.html#Get.Advanced.Selection


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 08-03-2010

[eluser]dejavu[/eluser]
[quote author="sixdimensionalarray" date="1280801917"]I have a table with a single primary integer key, but it is named "my_id", not "id" (for example).

Can DataMapper be extended to support a primary integer key for a table which is NOT named "id"? It is limited for use with existing tables that do not have a field named "id" and cannot be changed because they are already core tables which are supporting an existing codebase.

[/quote]
I'm not sure. http://www.overzealous.com/dmz/pages/joinfields.html#set_join_field may do what you want, but you'll have to try it out to make sure.


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 08-03-2010

[eluser]OverZealous[/eluser]
@sixdimensionalarray
It is not possible to change the ID column. it must be id on the model tables, and <relationship>_id on join tables and ITFKs.


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 08-04-2010

[eluser]patie[/eluser]
hi,

i have a problem

i need this query in DMZ..

Code:
SELECT user.*, order.*, SUM((order_album.price)*order_album.quantity) AS price
FROM order_album
LEFT JOIN order ON order_album.order_id = order.id
LEFT JOIN user ON order.user_id = user.id
GROUP BY order_album.order_id
ORDER BY order.id DESC

i have this :

User $table='user'; $has_many = array('order');
Order var $table = 'order'; var $has_one = array('user'); var $has_many = array('order_album');
Order_album var $table = 'order_album'; var $has_one = array('order');

Code:
$obj = new Order_album();
$obj->include_related('order', '*');
//$obj->include_related('user', '*'); // this join order_album with user, i need order with user
$obj->select('price * quantity AS price');
$obj->group_by('order_id');
$obj->order_by('order.id', 'DESC');
$obj->get();

this works

but i dont know how i join (in this "query") order.user_id with user.id - and dont order_album with user ...


thanks for any help.


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 08-04-2010

[eluser]WanWizard[/eluser]
Do I understand it correctly if I say that you have a many-to-many relationship between User and Order?

In that case your relationship table, that links users to orders, MUST be called Order_users (name of both tables, alphabetical order). You then have two models, one for User and one for Order. You don't need a model for your relationship table.

You then run the query like this:
Code:
$obj = new Order();
// add select and group_by where needed
$obj->include_related('user')->get_by_id($order_id);

You update fields in the relationship table by using:
Code:
// Create objects
$u = new User();
$u->get_by_id($user_id);

$o = new Order();
$o->get_by_id($order_id);

// update the order quantity to 100
$o->set_join_field($user, 'quantity', 100);



DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 08-04-2010

[eluser]patie[/eluser]
[quote author="WanWizard" date="1280951335"]Do I understand it correctly if I say that you have a many-to-many relationship between User and Order?

In that case your relationship table, that links users to orders, MUST be called Order_users (name of both tables, alphabetical order). You then have two models, one for User and one for Order. You don't need a model for your relationship table.

You then run the query like this:
Code:
$obj = new Order();
// add select and group_by where needed
$obj->include_related('user')->get_by_id($order_id);

You update fields in the relationship table by using:
Code:
// Create objects
$u = new User();
$u->get_by_id($user_id);

$o = new Order();
$o->get_by_id($order_id);

// update the order quantity to 100
$o->set_join_field($user, 'quantity', 100);
[/quote]

User - Order

i think it is not many-to-many because:

one user have many orders
but
one order have only one user (user_id)

i think it its one to many ? hmm