Welcome Guest, Not a member yet? Register   Sign In
[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition)

[eluser]bEz[/eluser]
Phil,

I already use a method which takes the ITFK (user_id) from the DMZ model "registration" and then via a library, I pull the userdata I need. I also use the Active Record method and do:
Code:
$object->query($sql);

I guess what I need is a work-around that will perform a join using both DMZ and AR methods from a DMZ object: (be mindful) I haven't tested this desperate request yet. :roll:

ie:

Events and Registrations both extend datamapper.
Registration has a "user_id" field which is a foreign key by theory to a table in another database.
What I would like is for every "event" obj. that has a related "registration" object, to get a result set which includes selected data from the "users" table as an object.

Quote:I think what I should do is:
---(A) get all $registrations related to the event(s)

and then

---(B) loop all()
-------- [1] convert each result as an array.
-------- [2] get the appropriate userdata based on the result->user-id, as an array
-------- [3] append both into a master array
This is just an explanation on what I'm looking for. No need to adjust your schedule quite yet, but thanks for re-directing my preliminary thoughts.
Oh, and the main reason for all this custom methods, is that the other database carries profile and other forum info that changes daily, weekly, etc.


-bEz

[eluser]OverZealous[/eluser]
@bEz
You can mix and match some of the CodeIgniter AR methods with DMZ. Just build the items like this:
Code:
$object->where('field', $value);
// AR method
$object->db->join(...);
$object->get();

Because DMZ usually calls the built-in AR methods, they will work together. You can even use DMZ query grouping (group_start/group_end) with AR methods! The only AR methods that won't work correctly (off the top of my head) are the AR versions of LIKE.

UPDATE: er... I'm wrong about one thing. You cannot use the DMZ group methods with AR methods. I forgot that I had to hack in some intelligence for query grouping. Sorry!

But, you can use the DMZ version of LIKE directly, as well as:
• where
• select
• select_(max|min|avg)
• like
• etc.
DMZ is fairly intelligent about when to add the table name and when not to.

But, as usual, try it, and see what breaks ;-)

[eluser]mandrake[/eluser]
[quote author="OverZealous" date="1258075125"][quote author="mandrake" date="1258065242"]It's possible generate with Datamapper a query like this:[/quote]

Was that a question? ;-)
...

But you didn't provide enough information. How are image and table related (1-to-N or 1-to-1)? If they are 1-to-1, you can include the columns from images in your results. If they are 1-to-N, there is no way in DMZ, currently, to include the columns. You'll have to run an extra query for each result to get those columns.

The next version of DMZ (yet to be released) will have support for subqueries, which could be used for this. You still won't be able to write compound JOIN statements, and I don't have any plans to include them.
...
[/quote]

Yes, it was a question.
Sorry for my English. :-(

The relation is 1-to-n.
Reading the documentation I had 'almost' understood that you could not do.
I just wanted a confirmation.

Thank you, awaiting the next version

AT@

[eluser]OverZealous[/eluser]
[quote author="mandrake" date="1258122625"]
Yes, it was a question.
Sorry for my English. :-([/quote]

No need for a frowny-face! I meant no disrespect — it was just funny to me! :-)

[eluser]bEz[/eluser]
By golly, I think I've got'it! :bug:

Code:
$registrations = new Registration();
$registrations->Distinct()   // Distinct() is not necessary, but I recall seeing it as an advised note in the DMZ Manual
  ->where_related('obj2/obj8/obj4', 'field1', 'VALUE')
  ->include_related('obj3', array('field2', 'field6'))
  ->include_related('obj5', array('field2'));

// Here is where I used AR methods (the key was to provide the fully qualified name of the db.table)
$registrations->db
  ->select('users.username As attendee')
  ->from('otherdb.users as users', 'users.user_id = registrations.user_id');

$registrations->get();

I was then able to loop as usual and
Code:
echo $r->attendee
using object notation.

The funny thing is that I've read other posts in this thread talking about the limited examples in the manual.
I think my problem was that I assumed my issue was on the abstract side, when in reality it was closer to the example provided (just thrown off on how to do a selection from another database).

I can now tuck away the $object->query($sql) until absolute need (which for now I don't see in the near future, **COUGH** 1.6 or eventually 2.0 ) Tongue

[eluser]OverZealous[/eluser]
Interesting that it is little more than another object prepended to the front (like a schema). I wonder how hard it would be to add another value (like $schema) that would be auto-prepended whenever an object is accessed ... it seems like it could be simply added in with the add_table_name method!

I'll have to think about it...

[eluser]tdktank59[/eluser]
Hey OverZealous

Im having an issue with your HTML form generation library.

Heres the code

The Controller
Code:
function register()
    {
        // Load up the user model
        $user = new User();
        
        if ($_POST)
        {
            [REMOVED Just handles the returning data with the from_array() method.]
        }    
                
        // Generate the form        
        $fields = array(
            'Account Registration' => 'section',
            'email_address',
            'confirm_email_address',
            'password' => array(
                'type' => 'password'
            ),
            'confirm_password' => array(
                'type' => 'password'
            ),
            'display_name',
            'first_name',
            'last_name'                
        );
        
        $url = 'auth/register';
        $options = array(
            'save_button' => 'Register',
            'reset_button' => 'Clear'
        );    
        
                // THIS METHOD DOES NOT
        $this->load->view('auth/form', array(
                'object' => $user,
                'fields' => $fields,
                'url' => $url,
                'options' => $options
            )
        );
        
                // THIS METHOD WORKS
        //echo $user->render_form($fields, $url, $options);
    }

The view
Code:
echo $object->render_form($fields, $url, $options);

The Error
Quote:Unable to load the requested file: dmz_htmlform/section.php

Looking in error logs nothing shows up that is not normal.
Whats odd is it only does this when I pass it off to the view to be rendered. If I echo it out in the controller it works fine.

[eluser]OverZealous[/eluser]
The error message you are seeing is because it can't find the view. If it works in the controller, then I don't know why it wouldn't work in the view. Obviously it works in the example app.

Are you running any CI libraries or extensions that might be changing the view? Do you have anything set up that isn't a normal CI setup?

[eluser]tdktank59[/eluser]
Just DMZ at the moment...
Otherwise everything else is normal...
Could it be a htaccess thing happening?

[eluser]pesho_h_k[/eluser]
Hello Smile

I just had a little problem and I think it's best if I ask you ...

So, I have page, and pagetexts - for different languages ... and when I try:

Code:
$page->pagestexts->get();

it gives me:

Unknown column `pagestexts`,`*` ...

And if I try

Code:
$page->pagestexts->select( '*', FALSE );
$page->pagestexts->get();

and it's all OK ... :question:

either I'm missing something, or ... its a little bit uncomfortable to do this every time on my own ...

Thanks in advance Smile




Theme © iAndrew 2016 - Forum software by © MyBB