Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Lost in ORM 10 Jan 2018 20:50 #15481

  • VeCrea
  • VeCrea's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
Hello guys, Happy New Year ;-)

Well to say i'm lost would be an understatement.
I believe i know my way around Cook, and I have done so many great things with it.
But i've spent the whole afternoon on this, and can't figure my way out.

I have USERS (joomla native feature), CLIENTS that are linked to those users (one user have many clients) and DEMANDS made by the clients.

I created a view to create a NEW DEMAND, with a field in the form that populates CLIENTS.

What i want to do is to only show CLIENTS that are linked to that USER.

I could do it the old and/or dirty way, but I'm trying to stay clean.

How could i achieve this ?
Thanks,
V.

Please Log in or Create an account to join the conversation.

Lost in ORM 12 Jan 2018 14:52 #15483

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
Happy New Year too

Happy to see you back Vinz !
I have been quite off recently as well

Well about ORM, what you need is the FILTER statement
See how it works here : www.j-cook.pro/index.php/o/orm-system#filter

Then if you still encounter a problem, then I will try to help you
For sure ORM do not handle 1:1 at the moment, but FILTER is customisable (even raw SQL filter)
Coding is now a piece of cake

Please Log in or Create an account to join the conversation.

Lost in ORM 12 Jan 2018 21:50 #15486

  • VeCrea
  • VeCrea's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
Oh mate...
I obviously looked at the documentation but you know I'm not much of a superb coder and the doc is... Sparse to say the least.

I think, if you have a little time for this, that we could work on this. It's not even that clear where you have to make modifications.

My needs for the project I'm building could be the base for a doc section with examples : what you need to use in the builder, what files you have to fork,...

I'm sure the whole or thing looks clean and easy to you, it certainly feels powerful and I have always been able to build great things with cook so I'm sure we'll figure it out once again.

Please Log in or Create an account to join the conversation.

Lost in ORM 15 Jan 2018 18:24 #15488

something like this should work:
 $userid = 100; // somehow get the userid, should be available in $this->item or $item, depending on where you are
		$this->orm(array(
			'select' => array(
				'id',
                                // etc.....
			),
			'relation' => array(
				'clients' => array(
					'select' => array(
						'name', // maybe other field?
						//other stuff
					),
					'filter' => array(
						'user' => array (
							'value' => $userid
						)
					)					
				),
			),
		));

Let me know if you need more help on where to put this code
The following user(s) said Thank You: VeCrea

Please Log in or Create an account to join the conversation.

Lost in ORM 15 Jan 2018 22:24 #15489

  • VeCrea
  • VeCrea's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
Thanks for your answer
I understand the code but where to place it after tweaking is the next question (should be the first maybe ;) )
The view.html.php contains :
$model_client = CkJModel::getInstance('Clients', 'CtrproModel');
$model_client->addGroupOrder("a.client");
$lists['fk']['client'] = $model_client->getItems();
That tells the list is populated by the "Clients" model.
In the "Clients" model, i can see the prepareQuery function but i don't think it's where to place it, or is the context thing ?

Please Log in or Create an account to join the conversation.

Lost in ORM 16 Jan 2018 08:40 #15490

I have solved something similar like this:
Instead of
$model_client = CkJModel::getInstance('Clients', 'CtrproModel');
$model_client->addGroupOrder("a.client");
$lists['fk']['client'] = $model_client->getItems();

Use:
$lists['fk']['client'] = CtrproHelper::getData('clients', array(
													'context' => '',
													'select' => array(
														'id',
														// etc.....
													),
													'relation' => array(
															'clients' => array(
																	'select' => array(
																	'name', // maybe other field?
																	//other stuff
																	),
															'filter' => array(
																	'user' => array (
																	'value' => JFactory::getUser()->id
																	)
															)					
															)
													)
												));

You could also create a new layout "ormLayoutClients" in your forked model with similar orm code and then use
$lists['fk']['client'] = CtrproHelper::getData('clients', array('context' => 'layout.clients'));

The context is used to set the layout :)
This last is is cleaner, because you can use it in other parts of the code without having to write the orm code again.

My way of working is to take it 1 little step at a time.
Rather then remove code right away I start with adding
$data = CtrproHelper::getData('clients', array());
var_dump($data);
Then when I see some data I add in more code, that way I can quickly spot when I make a mistake :)
The following user(s) said Thank You: VeCrea

Please Log in or Create an account to join the conversation.

Last edit: by Romkabouter.

Lost in ORM 16 Jan 2018 22:06 #15491

  • VeCrea
  • VeCrea's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
It kinda works. I will test it further, and when i get it to work exactly as i want, i'll post my results here.
Nog eens hartelijk bedankt maat

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.071 seconds

Just wanted to congratulate you on the J-Cook website / web development tool. In a couple of visits I've had a play around with Cook and have to say I think it is fantastic.  I've played with a number of component builders in the past and yours is certainly looking like the best so far. I'd also like to help you spread the word - I'm really surprised more people aren't excited about this tool. Good luck with the project.
Dean

Get Started