Relations Question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Relations Question

mister

I am trying to make a DVD catalog with Cake.  Right now i have a few
tables, dvds, genres, and ratings.  I already have setup the
scaffolding so that I can select a rating (G, PG, PG-13, R) from a drop
down list when I add a new DVD.  I want to do something very similar
for the genres, but I want to be able to select multiple genres for
each DVD.  Any suggestions?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Relations Question

John David Anderson (_psychic_)


On Nov 2, 2006, at 11:20 AM, [hidden email] wrote:

>
> I am trying to make a DVD catalog with Cake.  Right now i have a few
> tables, dvds, genres, and ratings.  I already have setup the
> scaffolding so that I can select a rating (G, PG, PG-13, R) from a  
> drop
> down list when I add a new DVD.  I want to do something very similar
> for the genres, but I want to be able to select multiple genres for
> each DVD.  Any suggestions?

Set up a hasAndBelongsToMany (HABTM) between DVDs and genres.

There should be some examples in the manual models chapter of how to  
accomplish this.

-- John



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Relations Question

Samuel DeVore
In reply to this post by mister

set it up as a hasAndBelongsToMany relationship then use bake.php and
you can see how to handle it from a code perspective.  Also I think
there is a article in the bakery.cakephp.org site on 'tags' that might
help

sam d

On 11/2/06, [hidden email] <[hidden email]> wrote:

>
> I am trying to make a DVD catalog with Cake.  Right now i have a few
> tables, dvds, genres, and ratings.  I already have setup the
> scaffolding so that I can select a rating (G, PG, PG-13, R) from a drop
> down list when I add a new DVD.  I want to do something very similar
> for the genres, but I want to be able to select multiple genres for
> each DVD.  Any suggestions?
>
>
> >
>


--
==
S. DeVore
(the old fart) the advice is free, the lack of crankiness will cost you

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Relations Question

mister

I have tried using the bake.php script with a Dvds hasAndBelongsToMany
Genres and it doesnt work.  When adding a new DVD, it has a text box
for me to enter the genre id number.  How should my dvds table be setup?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Re: Relations Question

Samuel DeVore

I'll assume that you have a dvds_genres table with dvd_id and genre_id
columns and the you have set up genre.php and dvd.php models to
hasAndBelongToMany each other

and that you have looked at the
http://manual.cakephp.org/chapter/models page down near the bottom
where it talks about this type of relation and that you have also
re-baked any views and controllers.  If so please post some code
samples to http://bin.cakephp.org/  (probably models, and at least one
controller and view) so we can see what you have done.


On 11/2/06, [hidden email] <[hidden email]> wrote:
>
> I have tried using the bake.php script with a Dvds hasAndBelongsToMany
> Genres and it doesnt work.  When adding a new DVD, it has a text box
> for me to enter the genre id number.  How should my dvds table be setup?
>
>
> >
>


--
==
S. DeVore
(the old fart) the advice is free, the lack of crankiness will cost you

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Relations Question

mister

Thank you.  The link helped a lot.  Now the only question i have is can
i have parent genres and sub-genres.  I thought that i read somewhere
that you can setup your tables with a parent_id field.  Any suggestions?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Re: Relations Question

Samuel DeVore

yes you can just use something like this
var $hasMany = array('ChildGenre' =>
array('className'=>'Genre','foreignKey'   => 'parent_genre_id'));
        var $belongsTo = array('ParentGenre' => array('className'=>'Genre'));

should get you started

On 11/2/06, [hidden email] <[hidden email]> wrote:
>
> Thank you.  The link helped a lot.  Now the only question i have is can
> i have parent genres and sub-genres.  I thought that i read somewhere
> that you can setup your tables with a parent_id field.  Any suggestions?
>
>
> >
>


--
==
S. DeVore
(the old fart) the advice is free, the lack of crankiness will cost you

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---