Sunday, June 10, 2012

Connect plugin models with main models

Hi,
I'm using CakePHP 2.1.
My main system has a User-model which I want to connect from within a
plugin model which is called SliderSlide.
So in the SliderSlide-model I want to define a belongsTo User
relationship but I don't want to define a hasMany SliderSlide in the
User model since the plugin might not be there.
In my SliderSlide model I now have:
public $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id'
)
);
but it seems that I can't access $sliderSlide['User']['id'] in the
SliderSlide views.
Notice (8): Undefined index: User
Also, putting the recursive parameter higher doesn't help.

Another problem I have, relates to the same problem I think:
In the SliderSlide model I have defined the following relationship:
public $hasMany = array(
'Upload' => array(
'className' => 'Upload',
'foreignKey' => 'model_id',
'dependent' => true,
'conditions' => array(
'Upload.plugin' => 'Slider',
'Upload.model' => 'SliderSlide'
)
)
);
where the Upload model is a model which resides in the main
application (and not in the Slider plugin, just like the a.m. User
model)
but when I delete a SliderSlide with:
public function delete($id = null, $cascade = true)
the cascaded Upload records are not deleted.

I have setup exactly the same for a ContentPage model which resides in
the main application and that is working very well.

So I have the following questions/problems to solve:

Q1: Is it ok to define a relationship only in one model without
defining it also in the related model?
Q2: Is it possible to integrate an if statement in the model class, so
I could check for the availability of a plugin first and then decide
to define the models relationship with the available plugin model?
Q3: How to relate a main model from within a plugin model?

Thanx for any help.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate