Re: retrieve related model data

2010-03-28 Thread sebb86
Thanks cricket.

Another addition, i someone else has a similar problem.
It also works without CONTAINABLE. Just keep the associations in the
model and the view code to retrieve and use the following in the
controller:

[code]
var $paginate = array(
'limit' => 50,
'order' => array('Port.hardware_unit_id' => 'asc'),
'recursive' => 2
  );
[/code]

Greetings.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: retrieve related model data

2010-03-26 Thread cricket
On Mar 26, 4:51 am, sebb86  wrote:
> in addition: in my view i retrieve this data in a foreach loop with
> this code:
> [view code]
>  NULL) { ?>  port id "; echo $port['Port']['uplink_id'];
> echo " (-> number: "; echo $port['ParentPort']['HardwareUnit']
> ['schenker_number']; echo ")"; } ?>

Great. For the self join model, you could go back to what you had
earlier, 'PortUplink', as the alias:

  var $hasOne = array(
   'PortUplink' => array(
   'className' => 'Port',
   'foreignKey' => 'uplink_id'
   )
  );

Just don't forget to change the 'contain' option and the view code if
you do.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: retrieve related model data

2010-03-26 Thread sebb86
in addition: in my view i retrieve this data in a foreach loop with
this code:
[view code]
  port id "; echo $port['Port']['uplink_id'];
echo " (-> number: "; echo $port['ParentPort']['HardwareUnit']
['schenker_number']; echo ")"; } ?>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: retrieve related model data

2010-03-26 Thread sebb86
Jeremy

It works with a little modification :) great!!!

The modification is to change "ChildPort" to "ParentPort" in the
following code:
[code]
var $paginate = array(
'fields' => array('*'),
'recursive' => 2,
'limit' => 50,
'order' => array('Port.hardware_unit_id' => 'asc'),
'contain' => array(
'ChildPort' =>
 array('HardwareUnit'),'HardwareUnit','Vlan','PortEmploymentGroup')
  );
[/code]


If you can see from the debug-output, the strange "0 array" isn't
there anymore and everything is right. :)
[debug output]
Array
(
[Port] => Array
(
[id] => 3
[hardware_unit_id] => 3
[vlan_id] => 2
[port_employment_group_id] => 3
[uplink_id] => 1
[active] => 0
[port_name] => 28
[port_index] => 0x26
[status] => 1
[duplex] => 10
[speed] => 100
[last_update] => 2009-03-12 11:30:21
[full_name] => 3 (28)
)

[HardwareUnit] => Array
(
[id] => 3
[staff_id] => 3
[room_id] => 3
[hardware_group_id] => 9
[hardware_type_id] => 2
[schenker_number] => 522
[active] => 1
[receptacle_port] =>
[serial_number] => 4gsd153-dg1253-6g351
[ip] =>
[user_login] =>
[purchase_date] => 2010-03-24
[support_end] =>
[leasing_end] =>
[additional_info] => das ist der zusatztext monitor
)

[Vlan] => Array
(
[id] => 2
[vlan_number] => 2
[description] => VLAN 43-FG
)

[PortEmploymentGroup] => Array
(
[id] => 3
[description] => PC
)

[ParentPort] => Array
(
[id] => 1
[hardware_unit_id] => 1
[vlan_id] => 1
[port_employment_group_id] => 3
[uplink_id] =>
[active] => 1
[port_name] => 24
[port_index] => 0x22
[status] => 1
[duplex] => 10
[speed] => 100
[last_update] => 2009-03-12 11:30:21
[HardwareUnit] => Array
(
[id] => 1
[staff_id] => 1
[room_id] => 1
[hardware_group_id] => 3
[hardware_type_id] => 4
[schenker_number] => 1000
[active] => 0
[receptacle_port] => 8a01
[serial_number] => 4153-1253-6351
[ip] => 192.168.178.55
[user_login] => admin
[purchase_date] => 2010-03-24
[support_end] => 2011-10-28
[leasing_end] =>
[additional_info] => das ist der zusatztext
)

)

)
[/debug output]

---
CRICKET and JEREMY -> thanks so much!
thanks! thanks! thanks! :-)

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: retrieve related model data

2010-03-26 Thread Jeremy Burns
The problem is (I think) that you are creating a self join but calling the 
joined model 'Port', which is the name of the current model.

Try changing to this (I've used ParentPort and ChildPort but you can rename at 
will):

> public $belongsTo = array(
>'HardwareUnit' => array(
>'className'  => 'HardwareUnit'
> ),
>'Vlan' => array(
>'className'  => 'Vlan'
> ),
>'PortEmploymentGroup' => array(
>'className'  => 'PortEmploymentGroup'
> ),
'ParentPort' => array(
'className' => 'Port',
'foreignKey' => 'uplink_id'
)
>   );

>   public $hasMany = array(
>'ChildPort' => array(
>'className' => 'Port',
>'foreignKey' => 'uplink_id'
>)
> );

> var $paginate = array(
>'fields' => array('*'),
>'recursive' => 2,
>'limit' => 50,
>'order' => array('Port.hardware_unit_id' => 'asc'),
>'contain' => array(
>'ChildPort' =>
> array('HardwareUnit'),'HardwareUnit','Vlan','PortEmploymentGroup')
>  );

Jeremy Burns
jeremybu...@me.com


On 26 Mar 2010, at 06:54, sebb86 wrote:

> sure! :-)
> 
> [code of model port]
> public $belongsTo = array(
>'HardwareUnit' => array(
>'className'  => 'HardwareUnit'
> ),
>'Vlan' => array(
>'className'  => 'Vlan'
> ),
>'PortEmploymentGroup' => array(
>'className'  => 'PortEmploymentGroup'
> )
>   );
> 
>   public $hasAndBelongsToMany = array(
>   'MacAddress' => array(
>   'className' => 'MacAddress',
>   'joinTable' => 'mac_addresses_ports',
>   'foreignKey' => 'port_id',
>   'associationForeignKey' => 'mac_address_id',
>   'unique' => true
>   )
>   );
> 
>   public $hasMany = array(
>'Port' => array(
>'className' => 'Port',
>'foreignKey' => 'uplink_id'
>)
> );
> [/code]
> 
> 
> Is that, what you want, when you ask to see the find statement? ->
> [controller code]
> var $paginate = array(
>'fields' => array('*'),
>'recursive' => 2,
>'limit' => 50,
>'order' => array('Port.hardware_unit_id' => 'asc'),
>'contain' => array(
>'Port' =>
> array('HardwareUnit'),'HardwareUnit','Vlan','PortEmploymentGroup')
>  );
> 
> 
> 
> function view()
>  {
>$this->set('ports', $this->paginate('Port'));
>  }
> [/code]
> 
> Check out the new CakePHP Questions site http://cakeqs.org and help others 
> with their CakePHP related questions.
> 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en
> 
> To unsubscribe from this group, send email to 
> cake-php+unsubscribegooglegroups.com or reply to this email with the words 
> "REMOVE ME" as the subject.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: retrieve related model data

2010-03-25 Thread sebb86
sure! :-)

[code of model port]
public $belongsTo = array(
'HardwareUnit' => array(
'className'  => 'HardwareUnit'
 ),
'Vlan' => array(
'className'  => 'Vlan'
 ),
'PortEmploymentGroup' => array(
'className'  => 'PortEmploymentGroup'
 )
   );

   public $hasAndBelongsToMany = array(
   'MacAddress' => array(
   'className' => 'MacAddress',
   'joinTable' => 'mac_addresses_ports',
   'foreignKey' => 'port_id',
   'associationForeignKey' => 'mac_address_id',
   'unique' => true
   )
   );

   public $hasMany = array(
'Port' => array(
'className' => 'Port',
'foreignKey' => 'uplink_id'
)
);
[/code]


Is that, what you want, when you ask to see the find statement? ->
[controller code]
var $paginate = array(
'fields' => array('*'),
'recursive' => 2,
'limit' => 50,
'order' => array('Port.hardware_unit_id' => 'asc'),
'contain' => array(
'Port' =>
array('HardwareUnit'),'HardwareUnit','Vlan','PortEmploymentGroup')
  );



function view()
  {
$this->set('ports', $this->paginate('Port'));
  }
[/code]

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: retrieve related model data

2010-03-25 Thread Jeremy Burns
Can you show me your entire $hasMany and $belongsTo declarations, and your find 
statement?

Jeremy Burns
jeremybu...@me.com

On 26 Mar 2010, at 06:24, sebb86 wrote:

> Jeremy Burns
> 
> Hello again :)
> Code in the model of my port-table:
> 
> (the $hasOne association from my origionally question was updated to
> the association below:)
> [code]
> public $hasMany = array(
>'Port' => array(
>'className' => 'Port',
>'foreignKey' => 'uplink_id'
>)
> );
> [/code]
> 
> I chose the alias "Port" because, when i try to call it different, for
> example "PortUplink", the following error occurs:
> Model "PortUplink" is not associated with model "Port" [CORE\cake\libs
> \model\behaviors\containable.php, line 340]
> 
> Check out the new CakePHP Questions site http://cakeqs.org and help others 
> with their CakePHP related questions.
> 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en
> 
> To unsubscribe from this group, send email to 
> cake-php+unsubscribegooglegroups.com or reply to this email with the words 
> "REMOVE ME" as the subject.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: retrieve related model data

2010-03-25 Thread sebb86
Jeremy Burns

Hello again :)
Code in the model of my port-table:

(the $hasOne association from my origionally question was updated to
the association below:)
[code]
public $hasMany = array(
'Port' => array(
'className' => 'Port',
'foreignKey' => 'uplink_id'
)
);
[/code]

I chose the alias "Port" because, when i try to call it different, for
example "PortUplink", the following error occurs:
Model "PortUplink" is not associated with model "Port" [CORE\cake\libs
\model\behaviors\containable.php, line 340]

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: retrieve related model data

2010-03-25 Thread Jeremy Burns
Do you have the self join set up inside your model? Something like this:

var $belongsTo = array(
'ParentPort' => array(
'className' => 'Port',
'foreignKey' => 'uplink_id'
)
);

Then you can include the ParentPort model in your contain array and extract 
data from it...I'm guessing but something like this:

> var $paginate = array(
>'fields' => array('*'),
>'recursive' => 2,
>'limit' => 50,
>'order' => array('Port.hardware_unit_id' => 'asc'),
>'contain' => array(
>'ParentPort' =>
> array('HardwareUnit',
'Port'
> ),'HardwareUnit','Vlan','PortEmploymentGroup')
>  );



Jeremy Burns
jeremybu...@me.com

On 26 Mar 2010, at 05:41, sebb86 wrote:

> I use this in my controller:
> [controller code]
> var $paginate = array(
>'fields' => array('*'),
>'recursive' => 2,
>'limit' => 50,
>'order' => array('Port.hardware_unit_id' => 'asc'),
>'contain' => array(
>'Port' =>
> array('HardwareUnit'),'HardwareUnit','Vlan','PortEmploymentGroup')
>  );
> 
> 
> 
> function view()
>  {
>$this->set('ports', $this->paginate('Port'));
>  }
> 
> I try to explain it again:
> The table "ports" (class: Port) contains the field "uplink_id". This
> is a self join from "uplink_id" as foreign-key to the primary key "id"
> from table "ports".
> Let's assume, a port has "id"=2 and the value from his "uplink_id" is
> 4. Then i need the HardwareUnit, which is associated with the port
> with primary key "id" = 4.
> If something is not understandable, simply ask again. My english is
> not very well. :/
> 
> ... and -cricket-, really thanks a lot for your help and patience.
> 
> Check out the new CakePHP Questions site http://cakeqs.org and help others 
> with their CakePHP related questions.
> 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en
> 
> To unsubscribe from this group, send email to 
> cake-php+unsubscribegooglegroups.com or reply to this email with the words 
> "REMOVE ME" as the subject.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: retrieve related model data

2010-03-25 Thread sebb86
I use this in my controller:
[controller code]
var $paginate = array(
'fields' => array('*'),
'recursive' => 2,
'limit' => 50,
'order' => array('Port.hardware_unit_id' => 'asc'),
'contain' => array(
'Port' =>
array('HardwareUnit'),'HardwareUnit','Vlan','PortEmploymentGroup')
  );



function view()
  {
$this->set('ports', $this->paginate('Port'));
  }

I try to explain it again:
The table "ports" (class: Port) contains the field "uplink_id". This
is a self join from "uplink_id" as foreign-key to the primary key "id"
from table "ports".
Let's assume, a port has "id"=2 and the value from his "uplink_id" is
4. Then i need the HardwareUnit, which is associated with the port
with primary key "id" = 4.
If something is not understandable, simply ask again. My english is
not very well. :/

... and -cricket-, really thanks a lot for your help and patience.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: retrieve related model data

2010-03-24 Thread cricket
On Mar 24, 11:57 am, sebb86  wrote:
> Jeremy
>
> Thanks! :) That works.
>
> But now, i thought i was ready i noticed another problem.
> The debug output above is for a port, which has no value in the field
> "uplink_id". But the port with "id" -> 3 has value 1 in "uplink_id".
> So port with id 3 points to port with id 1.
> Now, the problem is, that i need the "hardware_unit" in the table cell
> with the "uplink_id" (in my example port with id 3), not in the cell
> to which points this "uplink_id" (in my example port with id 1).
>
> Any ideas?
>
> [view retrieve code]
>  
>            "("; echo $port['Port']['0']['HardwareUnit']['schenker_number']; echo
> ")"; } ?>
> [/code]
>
> i despair of this problem :(

That doesn't work? It looks as though it should. Maybe I'm
misunderstanding your question.

But I don't understand why there's an array key 0. It should be
'PortUplink', I think. What was the exact find() you used?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: retrieve related model data

2010-03-24 Thread sebb86
Jeremy

Thanks! :) That works.

But now, i thought i was ready i noticed another problem.
The debug output above is for a port, which has no value in the field
"uplink_id". But the port with "id" -> 3 has value 1 in "uplink_id".
So port with id 3 points to port with id 1.
Now, the problem is, that i need the "hardware_unit" in the table cell
with the "uplink_id" (in my example port with id 3), not in the cell
to which points this "uplink_id" (in my example port with id 1).

Any ideas?

[view retrieve code]
 
  
[/code]

i despair of this problem :(

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: retrieve related model data

2010-03-24 Thread Jeremy Burns
To work this, start at the top and work your way down through the array:

$this->data['Port'][0]['HardwareUnit']['schenker_number']

Jeremy Burns
jeremybu...@me.com


On 24 Mar 2010, at 14:25, sebb86 wrote:

> cricket
> 
> Again... thanks a lot for your help.
> 
> It seems to work. When i debug, i get this:
> 
> ==
> Array
> (
>[Port] => Array
>(
>[id] => 1
>[hardware_unit_id] => 1
>[vlan_id] => 1
>[port_employment_group_id] => 3
>[uplink_id] =>
>[active] => 1
>[port_name] => 24
>[port_index] => 0x22
>[status] => 1
>[duplex] => 10
>[speed] => 100
>[last_update] => 2009-03-12 11:30:21
>[0] => Array
>(
>[id] => 3
>[hardware_unit_id] => 3
>[vlan_id] => 2
>[port_employment_group_id] => 3
>[uplink_id] => 1
>[active] => 0
>[port_name] => 28
>[port_index] => 0x26
>[status] => 1
>[duplex] => 10
>[speed] => 100
>[last_update] => 2009-03-12 11:30:21
>[HardwareUnit] => Array
>(
>[id] => 3
>[staff_id] => 3
>[room_id] => 3
>[hardware_group_id] => 9
>[hardware_type_id] => 2
>[schenker_number] => 522
>[active] => 1
>[receptacle_port] =>
>[serial_number] => 4gsd153-dg1253-6g351
>[ip] =>
>[user_login] =>
>[purchase_date] => 2010-03-24
>[support_end] =>
>[leasing_end] =>
>[additional_info] => das ist der
> zusatztext monitor
>)
> ===
> 
> Could you help me to find out the code to retrieve "schenker_number"
> in the last part?
> Currently i retrieve this way (in my view):
> [code inside a foreach loop]
>  td>
> [/code]
> 
> Thanks!
> 
> Check out the new CakePHP Questions site http://cakeqs.org and help others 
> with their CakePHP related questions.
> 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en
> 
> To unsubscribe from this group, send email to 
> cake-php+unsubscribegooglegroups.com or reply to this email with the words 
> "REMOVE ME" as the subject.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: retrieve related model data

2010-03-24 Thread sebb86
cricket

Again... thanks a lot for your help.

It seems to work. When i debug, i get this:

==
Array
(
[Port] => Array
(
[id] => 1
[hardware_unit_id] => 1
[vlan_id] => 1
[port_employment_group_id] => 3
[uplink_id] =>
[active] => 1
[port_name] => 24
[port_index] => 0x22
[status] => 1
[duplex] => 10
[speed] => 100
[last_update] => 2009-03-12 11:30:21
[0] => Array
(
[id] => 3
[hardware_unit_id] => 3
[vlan_id] => 2
[port_employment_group_id] => 3
[uplink_id] => 1
[active] => 0
[port_name] => 28
[port_index] => 0x26
[status] => 1
[duplex] => 10
[speed] => 100
[last_update] => 2009-03-12 11:30:21
[HardwareUnit] => Array
(
[id] => 3
[staff_id] => 3
[room_id] => 3
[hardware_group_id] => 9
[hardware_type_id] => 2
[schenker_number] => 522
[active] => 1
[receptacle_port] =>
[serial_number] => 4gsd153-dg1253-6g351
[ip] =>
[user_login] =>
[purchase_date] => 2010-03-24
[support_end] =>
[leasing_end] =>
[additional_info] => das ist der
zusatztext monitor
)
===

Could you help me to find out the code to retrieve "schenker_number"
in the last part?
Currently i retrieve this way (in my view):
[code inside a foreach loop]

[/code]

Thanks!

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: retrieve related model data

2010-03-23 Thread cricket
On Mar 23, 5:28 am, sebb86  wrote:
> Thanks for your help but i still dont get it working. sorry for my bad
> knowledge.

Ha! No worries. I'm certainly no expert.

> In my addModel, i added this line: [code]var $actsAs =
> array('Containable');[/code]
>
> In my controller i tryed this to use contain with paginate:
> [code]
> $this->set('ports', $this->paginate('Port', array('fields' =>
> array('*'), 'contain' => array('PortUplink' =>
> array('HardwareUnit');
> [/code]
> But i get lots of errors...for example, 'fields' is unknown.
> Greetings.


I see the problem. You must set the pagination options in the class
var $paginate. The *method* paginate() takes different params:

http://api.cakephp.org/class/controller#method-Controllerpaginate

The 2nd param there is for conditions. So, with what you did 'fields'
was passed in the SQL query literally and the DB complained it didn't
know about that column.

Try this:

var $paginate = array(
'Port' => array(
'fields' => array('*'),
'limit' => some number here,
'order' => array('Port.some_field' => 'ASC'),
'contain' => array(
'PortUplink' => array(
'HardwareUnit'
)
)
)
);

Of course, you can leave out the 'order' option.

In the action:

$this->set(
'ports',
$this->paginate('Port')
);


Search for "you can define more than one set of pagination defaults"
on this page:
http://book.cakephp.org/view/165/Controller-Setup

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: retrieve related model data

2010-03-23 Thread sebb86
Thanks for your help but i still dont get it working. sorry for my bad
knowledge.

In my addModel, i added this line: [code]var $actsAs =
array('Containable');[/code]

In my controller i tryed this to use contain with paginate:
[code]
$this->set('ports', $this->paginate('Port', array('fields' =>
array('*'), 'contain' => array('PortUplink' =>
array('HardwareUnit');
[/code]
But i get lots of errors...for example, 'fields' is unknown.
Greetings.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: retrieve related model data

2010-03-22 Thread cricket
On Mar 22, 12:23 pm, sebb86  wrote:
> cricket
>
> Thanks for your answer.
>
> Can i use "recursive" with pagination too?
> I need the pagination because of a sort auomatic in my view.

Yes. You can also use 'contain' in $paginate. I recommend doing that
as it's much more intuitive. You can set $actsAs =
array('Containable') in AppModel to have it available for all models.

> And despite of "debug", i really dont know how to retrive.
> I have to go the following way: uplink_id (table ports) -> id (table
> ports) -> hardware_unit_id (table ports) -> schenker_number (table
> hardware_units)

I think I'm beginning to understand. You want the HardwareUnit
associated with PortUplink, which is itself a self join on Port? Try
this:

array(
'fields' => array('*'),
'contain' => array(
'PortUplink' => array(
'HardwareUnit'
)
)
)


If you need the HardwareUnit for Port as well:

array(
'fields' => array('*'),
'contain' => array(
'HardwareUnit',
'PortUplink' => array(
'HardwareUnit'
)
)
)

If using recursive, try setting it to 2.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: retrieve related model data

2010-03-22 Thread sebb86
cricket

Thanks for your answer.

Can i use "recursive" with pagination too?
I need the pagination because of a sort auomatic in my view.

And despite of "debug", i really dont know how to retrive.
I have to go the following way: uplink_id (table ports) -> id (table
ports) -> hardware_unit_id (table ports) -> schenker_number (table
hardware_units)

Thanks again.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: retrieve related model data

2010-03-22 Thread cricket
Try playing with the 'recursive' param:

$data = $this->Port->find(
'first',
array(
'fields' => array('*'),
'recursive' => 2
)
);

$this->set(compact('data'));

Alternatively, if you are using ContainableBehavior (I recommend
setting AppModel to use it so it's always available) you can do this:

$data = $this->Port->find(
'first',
array(
'fields' => array('*'),
'contain' => array(
'HardwareUnit',
'PortUplink'
)
)
);

To see the data array:

die(debug($data));

I just noticed that you named your variable $ports, not $data. Adjust
as necessary.

On Mar 22, 7:53 am, sebb86  wrote:
> Hello,
> I'd like to show the following things in my view (respectively in the
> field uplink_id in the view): attribute "uplink_id" from table "ports"
> with attribute "schenker_number" from table "hardware_units".
> My problem are the associations, respectively i don't know the source
> code to retrieve the information i want.
>
> Fields:
> - "id" (table "ports" = primary-key)
> - "hardware_unit_id" (table "ports", = foreign-key associated with
> "id" from table "hardware_units")
> - "id" (table "hardware_units" = primary-key)
> - "uplink_id" (table "ports" = foreign-key associated with "id" from
> table "ports")
>
> Example with values:
> - "id" (table "ports") has value 4
> - "hardware_unit_id" has value 2 ---> "id" (table "hardware_units")
> has also value 2
> - "uplink_id" has value 1 (points to the "id" (table "ports" with
> value 1)
>
> So when i do this:
> {{{
> echo $port['HardwareUnit']['schenker_number'];
>
> }}}
>
> , i get the "schenker_number" from the hardware_unit, which is
> associated with the port ("id" = 4) BUT i need the "schenker_number"
> which matches with the "hardware_unit_id" from the port with "id"
> value 1 because of the "uplink_id" (value 1).
>
> **Model:**
> {{{
> class Port extends AppModel
> {
>   var $name= 'Port';
>
>   public $belongsTo = array(
>         'HardwareUnit' => array(
>         'className'  => 'HardwareUnit'
>          )
>    );
>
>    var $hasOne = array(
>     'PortUplink' => array(
>     'className' => 'Port',
>     'foreignKey' => 'uplink_id'
>     )
>    );
>
> }}}
>
> **Controller:**
> {{{
> class PortsController extends AppController
> {
>         var $name = 'Ports';
>         function index()
>         {
>                 $this->set('ports', $this->Port->find('all'));
>         }
>
> }}}
>
> **View:**
> {{{
> 
> 
> td>
>
> }}}
>
> Please don't hesitate to ask if i expressed myself unclearly.
> Thanks if someone can help.
> Greetings. :)

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.