Welcome Guest, Not a member yet? Register   Sign In
DataMapper 1.6.0

[eluser]PoetaWD[/eluser]
Another question... :S

Like, I have the Document object and related to it Document Type and Profiles(Clients) objects,

I want to build a HTML table that will have:


Id | Client Name | Document Type
--------------------------------------------
1 | Jonh | File
2 | Marie | Folder


In my controller:

Code:
$obj = new Documento();
//get all the documents from DB
$obj->get()->all;

//get all the related profiles
$obj->profiles->get()->all;    //???????????????????????????????????

//get all the related document types
$obj->Typesdocuments->get()->all;  //??????????????????????????????

//define $data as what ??
$data['objects'] = $obj->all; //?????????????????

In the view file:

Code:
foreach ($objetos as $lista)
{
   //write the ID of the document
    echo $lista->id
   //write the name of the client
    echo $lista->profile->stNome;
   //write the name of the Document Type
    echo $lista->Typesdocument->stNome;  
}

I am kind of lost now... dont even know where to look,,, Tongue .. you guys are my hope..

Thanks in advance

[eluser]OverZealous[/eluser]
OK, for starters, does Document have one or many Users? One or many Document Types? I would guess you only have one.

If you only have one, you don't need the ->all. You just do this (for example):
Code:
$type = $obj->typesdocuments->get();

As for your question, the original DataMapper doesn't provide a way to join these results. You will have to pass in all Documents to your view, then loop through each document, get() the user and type, and process them:
Code:
<? foreach($documents as $doc):
     $doc->profiles->get(); // adds a query for each $doc
     $doc->typesdocuments->get(); // adds another query for each $doc
    ?> output data here <?= htmlspecialchars($doc->profiles->name) ?>
<? endforeach; ?>

If you were to try DMZ, you could actually include columns from $has_one related items and reduce your number of queries substantially. It would look like this in the controller:
Code:
$documents->include_related('profile', array('name')); // include just the name column
$documents->include_related('typesdocument', '*'); // include all of the type columns
$documents->get();

And this is your view:
Code:
<? foreach($documents as $doc): ?>
<tr>
    <td>&lt;?= htmlspecialchars($doc->id) ?&gt;</td>
    <td>&lt;?= htmlspecialchars($doc->profile_name) ?&gt;</td>
    <td>&lt;?= htmlspecialchars($doc->typesdocument_name) ?&gt;</td>
</tr>
&lt;? endforeach; ?&gt;

I don't have everything labeled the same, so I apologize if that trips you up.

Also, a suggestion:
1) Make sure you name your variables correctly. It's confusing (for me at least) to have a variable called $objetos, because there is no meaning to your variable. If you had called it $documents (or whatever is correct in your language) – and passed it in as 'documents' – it would be easier for you to read and any developers down the road.

[eluser]PoetaWD[/eluser]
Thanks MAN !

Now I understand why the DMZ is better !

I will update right now !

I will also try to do as you said and post the results here !

Thank you very much for the quick help !


Update:

As quick as it was... IT WORKED !!!

Much better !!!! Thank you !!!

I guess that I will have to post questions in the DMZ topic !

Thank you man ! This is great !

[eluser]tdktank59[/eluser]
@OverZealous

If Im not mistaken his variables are in spanish. So they do have meaning lol... (I know it was trippen me up too.)

[eluser]OverZealous[/eluser]
Yes, well, objetos = objects, I assume, so it doesn't really reflect the meaning of 'documentos' or 'perfiles'. That was the point of my suggestion, not a language issue.

[eluser]PoetaWD[/eluser]
Those are portuguese words... Tongue

I am from Brazil...

Where u guys from ?

Btw

I keep going with the development of the application... so far so good... thanks for the help you are giving me.

[eluser]OverZealous[/eluser]
I'm from Michigan, USA. But I work overnight usually, so I'm up with the Aussies and Kiwis. :-)

[eluser]PoetaWD[/eluser]
[quote author="OverZealous.com" date="1246006885"]I'm from Michigan, USA. But I work overnight usually, so I'm up with the Aussies and Kiwis. :-)[/quote]

Hey man !

I work at night too... not a fix job.. I work as a webdesigner in my free time. I am still a student, I spent 2 years of my life in medical school... but got tired...

Now I am going to civil engineering.. but most of my time I spend in the computer...

I got tired of PAYING other people to do my programing work.. so I am learning... It is pretty easy to learn the language... the hard is to get the tricks...

I am realizing that experience is 99% of programing...

Well thanks for helping me...

I am trying to think something that I might have that would interest you since I dont have any money to donate... Sad

I have a premium rapidshare account that I might be able to share with you ?
I also have a premium account at dreamtemplate.com . You can ask me any template and I will send it in your email.

Hehe... I know that is not much and that you didnt ask.. but I like you and would like to give you something in exchange for your help.

Big Grin

[eluser]OverZealous[/eluser]
You could send me a souvenir from Brazil! My wife actually has some friends in Brazil, but she always gets cool stuff, not me ;-) Of course, that's probably too expensive, anyway!

What part of Brazil are you from?

Otherwise, I host my own server (I have a business plan for my home, which is nice), and I do a lot of my own graphic design :cheese:

[eluser]PoetaWD[/eluser]
[quote author="OverZealous.com" date="1246010554"]You could send me a souvenir from Brazil! My wife actually has some friends in Brazil, but she always gets cool stuff, not me ;-) Of course, that's probably too expensive, anyway!

What part of Brazil are you from?

Otherwise, I host my own server (I have a business plan for my home, which is nice), and I do a lot of my own graphic design :cheese:[/quote]

I sure can !

I do too most of my work... but something I need some "inpiration" a place to start... so I go there, in the template website,,

Hehe ...

I am from Belo Horizonte... not near the beach... more in the center of brazil.

I lived one year in US as a exchange student, in Virginia... It was pretty cool... I love US... I plan (DREAM) going back one day... maybe after I finish college...

Just tell me what u want and i´ll try to send you... hehe :-)

I am done for today.. 3am here...

See ya




Theme © iAndrew 2016 - Forum software by © MyBB