You're correct,  I did end up defining the relationship within the
plugin and that does indeed make it less app-agnostic.   It's a
balancing act, ideally you want your plugin to be completely self
reliant, but if that's not the goal of your app you need to decide how
much is too much?  My InstantMessenger assumes there is a User model
because I think that's a fair requirement and assumption for a my
plugin to make, a plugin that specialize is getting to two User's to
talk to one another.  But if you're getting to the point in your
plugin that it really needs to have intimate relationships with your
app models its probably time to stop trying to make it a plugin and
just make the functionality part of your app.

Just my opinion,
Nick

On Mar 7, 11:43 am, "iamcam (Cameron Perry)" <[email protected]>
wrote:
> Nick,
>
> Correct me if I'm wrong... You ended up creating the association
> inside the chat plugin anyway - like any other model-to-model
> relationship? I wonder if I'm being too strict in trying to keep the
> plugin too app-agnostic. And the truth is, in the current app I have,
> there are other app-specific hasMany gallery that the plugin should
> never know about so it remains portable. How do you see that changing
> the relationship? I was considering trying the hasMany :through
> relationship that a couple Cake bloggers have talked about (appears
> similar to HABTM, but not). That could possibly solve the issue
> besides just creating the Gallery install requirement to add the
> appropriate model relationships back to the app - just cuts down on
> the portability.
>
> Thanks!
> Cameron
>
> On Mar 6, 5:58 pm, nurvzy <[email protected]> wrote:
>
> > This is how I do it in my InstantMessenger plugin which relates to the
> > User model of the App.
>
> > //plugins/instant_messenger/models/im_chat.php
> > var $belongsTo = array(
> >     'ImSession' => array(
> >       'className' => 'InstantMessenger.ImSession',
> >       'dependant' => true
> >     ),
> >     'User' => array(
> >       'className' => 'User'
> >     )
> >   );
>
> > //app/models/user.php
> > var $hasMany = array(
> >   'Chat' => array(
> >     'className' => 'InstantMessenger.ImChat',
> >   )
> > );
>
> > Now I have an alias model of Chat for my User model that relates to
> > the plugin/model/im_chat.
>
> > Hope that helps,
> > Nick
> > On Mar 6, 9:50 am, "iamcam (Cameron Perry)" <[email protected]>
> > wrote:> This might be elementary for some, but I haven't quite wrapped my 
> > head
> > > around how I can build a hasMany relationship from my app model to a
> > > model in a plugin (one I'm also writing).
>
> > > The basic gist looks something like this:
>
> > > /** App's User Model **/
> > > class User extends AppModel {
> > >         var $name = 'User';
> > >         var $hasMany = array('Gallery.Gallery'); // you get the point
>
> > > }
>
> > > /** Gallery Plugin's Gallery Model **/
> > > class Gallery extends GalleryAppModel {
> > >         var $name = 'Gallery';
> > >         var $belongsTo = array( ... ); //other plugin models
>
> > > }
>
> > > /*********************************************************/
>
> > > So what I want to do is basically get a list of all the galleries
> > > associated with a user. I know how to do that if the gallery is built
> > > in to the app, but since I'm trying to make it modular I'm a little
> > > stumped. PS: There are other app models that will also have a hasMany
> > > relationship to gallery, so I want to do the right thing.
>
> > > I'm in the mindset that plugins aren't meant to be messed with (too
> > > much) to integrate them into your app, so it doesn't seem like a good
> > > idea to me to start adding foreign key fields in the gallery model
> > > (like user_id or tag_id).  I considered creating a HABTM on my app
> > > side so I at least have a join table where I can match the two sets of
> > > foreign keys. Am I wrong about either of these?
>
> > > So the big question - How do I do this? Does anyone else figured this
> > > out before?
>
> > > Thanks so much in advance! This community has been very good to me in
> > > the past.
>
> > > ~Cameron

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 [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to