Re: Multiple hasMany relationships to one model?
Brian - that'd be a good option if an image can belong to many movies and many episodes. Adam - is that the case? Or can an image only belong to either 1 movie or 1 episode? From the description you put up it sounds like hasMany is the right association, it's just making a good db design underneath it. On Mar 31, 9:39 am, brian wrote: > I'd go HABTM for this, I think. > > movies > videos > images > images_movies > images_videos > > > > On Tue, Mar 31, 2009 at 2:09 AM, Adam M wrote: > > > Hi All, > > > How can I PROPERLY set up my database so that several models have > > multiple images? Each image belongs to a particular model, so they > > are definitely hasMany relationships. Example: > > > Episode > > -id > > -name > > -date > > > Movie > > -id > > -name > > -date > > -producer > > > Image > > -id > > -name > > -caption > > -path > > > Episode hasMany Image > > Movie hasMany Image > > > Does the paradigm of adding a foreign key to the Image table still > > apply if I have multiple hasMany relationships? That is, would I add > > multiple foreign keys to the table as follows?: > > Image > > -id > > -movie_id > > -episode_id > > -name > > -caption > > -path > > > Thanks --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Multiple hasMany relationships to one model?
I'd go HABTM for this, I think. movies videos images images_movies images_videos On Tue, Mar 31, 2009 at 2:09 AM, Adam M wrote: > > Hi All, > > How can I PROPERLY set up my database so that several models have > multiple images? Each image belongs to a particular model, so they > are definitely hasMany relationships. Example: > > Episode > -id > -name > -date > > Movie > -id > -name > -date > -producer > > Image > -id > -name > -caption > -path > > Episode hasMany Image > Movie hasMany Image > > Does the paradigm of adding a foreign key to the Image table still > apply if I have multiple hasMany relationships? That is, would I add > multiple foreign keys to the table as follows?: > Image > -id > -movie_id > -episode_id > -name > -caption > -path > > Thanks > > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Multiple hasMany relationships to one model?
You have a couple options here. What's "proper" is really what works best in your situation, so do some testing to see how the queries perform. I had a similar situation so I'll explain what I did. Video - id Episode - video_id - name - date Movie - video_id - name - date - producer Image - id - name - caption - path - video_id Video hasMany Episode Video hasMany Movie Episode hasMany Image Movie hasMany Image In this design Video is the parent of Episode and Movie and generates unique ids for them. These ids can then be added to any tables associated to Episode or Movie. On top of that you can setup foreign keys in MySQL so that when you delete a Video to cascades and deletes all related data. On Mar 31, 1:09 am, Adam M wrote: > Hi All, > > How can I PROPERLY set up my database so that several models have > multiple images? Each image belongs to a particular model, so they > are definitely hasMany relationships. Example: > > Episode > -id > -name > -date > > Movie > -id > -name > -date > -producer > > Image > -id > -name > -caption > -path > > Episode hasMany Image > Movie hasMany Image > > Does the paradigm of adding a foreign key to the Image table still > apply if I have multiple hasMany relationships? That is, would I add > multiple foreign keys to the table as follows?: > Image > -id > -movie_id > -episode_id > -name > -caption > -path > > Thanks --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Multiple hasMany relationships to one model?
Hi All, How can I PROPERLY set up my database so that several models have multiple images? Each image belongs to a particular model, so they are definitely hasMany relationships. Example: Episode -id -name -date Movie -id -name -date -producer Image -id -name -caption -path Episode hasMany Image Movie hasMany Image Does the paradigm of adding a foreign key to the Image table still apply if I have multiple hasMany relationships? That is, would I add multiple foreign keys to the table as follows?: Image -id -movie_id -episode_id -name -caption -path Thanks --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: how to do multiple hasmany
You need to combine them both into 1 hasMany array: var $hasMany = array( 'Childclass1' => array( 'className' => 'Childclass1' ), 'Childclass2' => array( 'className' => 'Childclass2' ) ); On Aug 22, 12:43 am, robert123 <[EMAIL PROTECTED]> wrote: > i have parent model, it has two hasmany child model, > > in the model class, I tried to model this relation by writing two time > in the parent model class > > var $hasMany = array('Childclass1' => >array('className' => > 'Childclass1'); > > var $hasMany = array('Childclass2' => >array('className' => > 'Childclass2'); > > but it giving me the below error > Cannot redeclare Childclass2::$hasMany > > anyone can let me know, how to solve this, thank you > > http://www.generics.ws/jpn/レビトラ(塩酸バルデナフィルHCL_)に20_MGについて-p-115.htmlhttp://www.generics.ws/jpn/プロペシア(フィナステライド)-p-4.htmlhttp://www.generics.ws/jpn/バイアグラ(クエン酸シルデナフィル)-p-2.html --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
how to do multiple hasmany
i have parent model, it has two hasmany child model, in the model class, I tried to model this relation by writing two time in the parent model class var $hasMany = array('Childclass1' => array('className' => 'Childclass1'); var $hasMany = array('Childclass2' => array('className' => 'Childclass2'); but it giving me the below error Cannot redeclare Childclass2::$hasMany anyone can let me know, how to solve this, thank you http://www.generics.ws/jpn/レビトラ(塩酸バルデナフィルHCL_)に20_MGについて-p-115.html http://www.generics.ws/jpn/プロペシア(フィナステライド)-p-4.html http://www.generics.ws/jpn/バイアグラ(クエン酸シルデナフィル)-p-2.html --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: multiple "hasMany"?
> > alright it appears that the associations are working correctly, but > > the scaffolding just isn't being generated for notes. oh well I guess hey Luke, any progress? cheers, jon -- jon bennett w: http://www.jben.net/ iChat (AIM): jbendotnet Skype: jon-bennett --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: multiple "hasMany"?
> alright it appears that the associations are working correctly, but > the scaffolding just isn't being generated for notes. oh well I guess hmm, doesn't make sense, I don't this is a bug, it's used to often by too many. Please paste the code for your models in the bin: http://bin.cakephp.org/add/ cheers, jon -- jon bennett w: http://www.jben.net/ iChat (AIM): jbendotnet Skype: jon-bennett --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: multiple "hasMany"?
alright it appears that the associations are working correctly, but the scaffolding just isn't being generated for notes. oh well I guess On Nov 30, 1:23 pm, "Jon Bennett" <[EMAIL PROTECTED]> wrote: > On 30/11/2007, Luke <[EMAIL PROTECTED]> wrote: > > > > > no that would only allow me to have one note and one item per order... > > I want many items and many notes per order... so I put order_id inside > > each of those tables. > > oh yeah, doh! > > it's even easier then, the issue is most likely cause by cake's > scaffolding assuming alphabetically, eg, 'i' before 'n' orderItem > before orderNote! this is why your associations work when you do: > > class Order extends AppModel > { > var $name = 'Order'; > var $hasMany = array( > 'OrderItem'=>array('dependent'=>true), > 'OrderNote' => array('dependent'=>true) > ); > > } > > hth > > jon > > -- > > jon bennett > w:http://www.jben.net/ > iChat (AIM): jbendotnet Skype: jon-bennett --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: multiple "hasMany"?
On 30/11/2007, Luke <[EMAIL PROTECTED]> wrote: > > no that would only allow me to have one note and one item per order... > I want many items and many notes per order... so I put order_id inside > each of those tables. oh yeah, doh! it's even easier then, the issue is most likely cause by cake's scaffolding assuming alphabetically, eg, 'i' before 'n' orderItem before orderNote! this is why your associations work when you do: class Order extends AppModel { var $name = 'Order'; var $hasMany = array( 'OrderItem'=>array('dependent'=>true), 'OrderNote' => array('dependent'=>true) ); } hth jon -- jon bennett w: http://www.jben.net/ iChat (AIM): jbendotnet Skype: jon-bennett --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: multiple "hasMany"?
I think his tables are ok (he posted them here a couple of messages before). orders: id date customer_name customer_phone customer_etc total order_items: id order_id name description price sku order_notes: order_id note date 2007/11/30, Jon Bennett <[EMAIL PROTECTED]>: > > > do you mean my table names? > > no > > I'm assuming your orders table is: > > Order > - id > - order_item_id > - order_note_id > - created > - modified > > and you have in your order model > > class Order extends AppModel { > var $name = 'Order'; > > var $hasMany = array( > 'OrderNote' => array( > > 'className' => 'OrderNote', > 'dependent' => true, > > ), > > 'OrderItem' => array( > > 'className' => 'OrderItem', > 'dependent' => true, > > ) > ); > } > > is that correct? > > cheers, > > jon > > > -- > > jon bennett > w: http://www.jben.net/ > iChat (AIM): jbendotnet Skype: jon-bennett > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: multiple "hasMany"?
no that would only allow me to have one note and one item per order... I want many items and many notes per order... so I put order_id inside each of those tables. On Nov 30, 1:16 pm, "Jon Bennett" <[EMAIL PROTECTED]> wrote: > > do you mean my table names? > > no > > I'm assuming your orders table is: > > Order > - id > - order_item_id > - order_note_id > - created > - modified > > and you have in your order model > > class Order extends AppModel { > var $name = 'Order'; > > var $hasMany = array( > 'OrderNote' => array( > > 'className' => 'OrderNote', > 'dependent' => true, > > ), > > 'OrderItem' => array( > > 'className' => 'OrderItem', > 'dependent' => true, > > ) > ); > > } > > is that correct? > > cheers, > > jon > > -- > > jon bennett > w:http://www.jben.net/ > iChat (AIM): jbendotnet Skype: jon-bennett --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: multiple "hasMany"?
> do you mean my table names? no I'm assuming your orders table is: Order - id - order_item_id - order_note_id - created - modified and you have in your order model class Order extends AppModel { var $name = 'Order'; var $hasMany = array( 'OrderNote' => array( 'className' => 'OrderNote', 'dependent' => true, ), 'OrderItem' => array( 'className' => 'OrderItem', 'dependent' => true, ) ); } is that correct? cheers, jon -- jon bennett w: http://www.jben.net/ iChat (AIM): jbendotnet Skype: jon-bennett --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: multiple "hasMany"?
do you mean my table names? On Nov 30, 1:09 pm, "Dardo Sordi Bogado" <[EMAIL PROTECTED]> wrote: > Try defining your model classes whitout the 'order_' prefix, and set > $useTable = 'order_whatever'; in the model. > > 2007/11/30, Luke <[EMAIL PROTECTED]>: > > > > > umm I might have asked the question wrong. here is what I am trying to > > do: > > > I have 3 tables: orders, order_items, and order_notes > > > Orders is full of all of my store's orders. Order items are all the > > items the customer purchased, and order_notes contains all of the > > notes associated with an order. so the tables look like: > > > orders: > > > id > > date > > customer_name > > customer_phone > > customer_etc > > total > > > order_items: > > > id > > order_id > > name > > description > > price > > sku > > > order_notes: > > order_id > > note > > date > > > So it isn't a many-to-many association, it's just two one-to-many > > associates. > > > On Nov 30, 9:17 am, Anupom <[EMAIL PROTECTED]> wrote: > > > Join tables should be named after the tables that will join, in > > > alphabetical order, with underscores in between. As an example, a join > > > table between posts and tags tables should be named posts_tags, not > > > tags_posts. > > > > The default value of the foreign keys used in the join table must be > > > underscored, singular name of the models in relation, suffixed with > > > '_id'. > > > Like, post_id, tag_id. > > > > If you want to override the defaults, you can explicitly define it in > > > the association attribute of the model - > > > > > > class Post extends AppModel > > > { > > > var $name = 'Post'; > > > > var $hasAndBelongsToMany = array( > > > 'Tag' => > > > array('className'=> 'Tag', > > > 'joinTable' => 'tags_posts, //altered the > > > default - posts_tags > > > 'foreignKey' => 'article_id', //altered > > > the default -post_id > > > 'associationForeignKey' => 'category_id' //altered > > > the default - tag_id > > > ) > > > );} > > > > ?> > > > > On Nov 30, 2007 11:12 PM, Jon Bennett <[EMAIL PROTECTED]> wrote: > > > > > > Always best to stick to a A-Z (why can't I think of the correct term > > > > > for that!) > > > > > ALPHABETICAL > > > > > cheers, > > > > > jon > > > > > -- > > > > > jon bennett > > > > w:http://www.jben.net/ > > > > iChat (AIM): jbendotnet Skype: jon-bennett > > > > -- > > > Thanks > > > Anupom > > > Trippert Inc. [http://www.trippert.com] > > > GopherNow. [http://www.gophernow.com/] > > > Homepage. [http://www.anupom.wordpress.com/] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: multiple "hasMany"?
> So it isn't a many-to-many association, it's just two one-to-many > associates. as I stated in my previous reply, the problem is to do with the order in which your foreign keys are listed in the Orders table, and the fact your associations are mapped in a different order. This is why when you swap the order of the associations in your Order model it works. Always best to do everything alphabetically. cheers, jon -- jon bennett w: http://www.jben.net/ iChat (AIM): jbendotnet Skype: jon-bennett --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: multiple "hasMany"?
Try defining your model classes whitout the 'order_' prefix, and set $useTable = 'order_whatever'; in the model. 2007/11/30, Luke <[EMAIL PROTECTED]>: > > umm I might have asked the question wrong. here is what I am trying to > do: > > I have 3 tables: orders, order_items, and order_notes > > Orders is full of all of my store's orders. Order items are all the > items the customer purchased, and order_notes contains all of the > notes associated with an order. so the tables look like: > > orders: > > id > date > customer_name > customer_phone > customer_etc > total > > order_items: > > id > order_id > name > description > price > sku > > order_notes: > order_id > note > date > > So it isn't a many-to-many association, it's just two one-to-many > associates. > > On Nov 30, 9:17 am, Anupom <[EMAIL PROTECTED]> wrote: > > Join tables should be named after the tables that will join, in > > alphabetical order, with underscores in between. As an example, a join > > table between posts and tags tables should be named posts_tags, not > > tags_posts. > > > > The default value of the foreign keys used in the join table must be > > underscored, singular name of the models in relation, suffixed with > > '_id'. > > Like, post_id, tag_id. > > > > If you want to override the defaults, you can explicitly define it in > > the association attribute of the model - > > > > > class Post extends AppModel > > { > > var $name = 'Post'; > > > > var $hasAndBelongsToMany = array( > > 'Tag' => > > array('className'=> 'Tag', > > 'joinTable' => 'tags_posts, //altered the > > default - posts_tags > > 'foreignKey' => 'article_id', //altered > > the default -post_id > > 'associationForeignKey' => 'category_id' //altered > > the default - tag_id > > ) > > );} > > > > ?> > > > > On Nov 30, 2007 11:12 PM, Jon Bennett <[EMAIL PROTECTED]> wrote: > > > > > > > > > > > > > > Always best to stick to a A-Z (why can't I think of the correct term > > > > for that!) > > > > > ALPHABETICAL > > > > > cheers, > > > > > jon > > > > > -- > > > > > jon bennett > > > w:http://www.jben.net/ > > > iChat (AIM): jbendotnet Skype: jon-bennett > > > > -- > > Thanks > > Anupom > > Trippert Inc. [http://www.trippert.com] > > GopherNow. [http://www.gophernow.com/] > > Homepage. [http://www.anupom.wordpress.com/] > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: multiple "hasMany"?
umm I might have asked the question wrong. here is what I am trying to do: I have 3 tables: orders, order_items, and order_notes Orders is full of all of my store's orders. Order items are all the items the customer purchased, and order_notes contains all of the notes associated with an order. so the tables look like: orders: id date customer_name customer_phone customer_etc total order_items: id order_id name description price sku order_notes: order_id note date So it isn't a many-to-many association, it's just two one-to-many associates. On Nov 30, 9:17 am, Anupom <[EMAIL PROTECTED]> wrote: > Join tables should be named after the tables that will join, in > alphabetical order, with underscores in between. As an example, a join > table between posts and tags tables should be named posts_tags, not > tags_posts. > > The default value of the foreign keys used in the join table must be > underscored, singular name of the models in relation, suffixed with > '_id'. > Like, post_id, tag_id. > > If you want to override the defaults, you can explicitly define it in > the association attribute of the model - > > class Post extends AppModel > { > var $name = 'Post'; > > var $hasAndBelongsToMany = array( > 'Tag' => > array('className'=> 'Tag', > 'joinTable' => 'tags_posts, //altered the > default - posts_tags > 'foreignKey' => 'article_id', //altered > the default -post_id > 'associationForeignKey' => 'category_id' //altered > the default - tag_id > ) > );} > > ?> > > On Nov 30, 2007 11:12 PM, Jon Bennett <[EMAIL PROTECTED]> wrote: > > > > > > > > Always best to stick to a A-Z (why can't I think of the correct term for > > > that!) > > > ALPHABETICAL > > > cheers, > > > jon > > > -- > > > jon bennett > > w:http://www.jben.net/ > > iChat (AIM): jbendotnet Skype: jon-bennett > > -- > Thanks > Anupom > Trippert Inc. [http://www.trippert.com] > GopherNow. [http://www.gophernow.com/] > Homepage. [http://www.anupom.wordpress.com/] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: multiple "hasMany"?
Join tables should be named after the tables that will join, in alphabetical order, with underscores in between. As an example, a join table between posts and tags tables should be named posts_tags, not tags_posts. The default value of the foreign keys used in the join table must be underscored, singular name of the models in relation, suffixed with '_id'. Like, post_id, tag_id. If you want to override the defaults, you can explicitly define it in the association attribute of the model - array('className'=> 'Tag', 'joinTable' => 'tags_posts, //altered the default - posts_tags 'foreignKey' => 'article_id', //altered the default -post_id 'associationForeignKey' => 'category_id' //altered the default - tag_id ) ); } ?> On Nov 30, 2007 11:12 PM, Jon Bennett <[EMAIL PROTECTED]> wrote: > > > Always best to stick to a A-Z (why can't I think of the correct term for > > that!) > > ALPHABETICAL > > > cheers, > > jon > > -- > > jon bennett > w: http://www.jben.net/ > iChat (AIM): jbendotnet Skype: jon-bennett > > > > -- Thanks Anupom Trippert Inc. [http://www.trippert.com] GopherNow. [http://www.gophernow.com/] Homepage. [http://www.anupom.wordpress.com/] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: multiple "hasMany"?
> Always best to stick to a A-Z (why can't I think of the correct term for > that!) ALPHABETICAL cheers, jon -- jon bennett w: http://www.jben.net/ iChat (AIM): jbendotnet Skype: jon-bennett --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: multiple "hasMany"?
> Does cake not allow multiple "hasMany" associations? for some reason > it is only rendering scaffolding for the first of the two I'm putting > in here: > > class Order extends AppModel { >var $name = 'Order'; > >var $hasMany = array( > 'OrderNote' => array( > >'className' => 'OrderNote', >'dependent' => true, > > ), > > 'OrderItem' => array( > >'className' => 'OrderItem', >'dependent' => true, > > ) > ); > } > > if I switch the two and make OrderItem first, then that shows up in > the scaffolding. What's the deal?? I think scaffolding works by matching the order of the foreign keys in your db table with your assocaitions. Always best to stick to a A-Z (why can't I think of the correct term for that!) and you'll go no wrong (as you've proved!) cheers, jon -- jon bennett w: http://www.jben.net/ iChat (AIM): jbendotnet Skype: jon-bennett --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: multiple "hasMany"?
does nobody know or is it impossible or what? On Nov 29, 3:39 pm, Luke <[EMAIL PROTECTED]> wrote: > Does cake not allow multiple "hasMany" associations? for some reason > it is only rendering scaffolding for the first of the two I'm putting > in here: > > class Order extends AppModel { >var $name = 'Order'; > >var $hasMany = array( > 'OrderNote' => array( > >'className' => 'OrderNote', >'dependent' => true, > > ), > > 'OrderItem' => array( > >'className' => 'OrderItem', >'dependent' => true, > > ) > ); > > } > > if I switch the two and make OrderItem first, then that shows up in > the scaffolding. What's the deal?? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
multiple "hasMany"?
Does cake not allow multiple "hasMany" associations? for some reason it is only rendering scaffolding for the first of the two I'm putting in here: class Order extends AppModel { var $name = 'Order'; var $hasMany = array( 'OrderNote' => array( 'className' => 'OrderNote', 'dependent' => true, ), 'OrderItem' => array( 'className' => 'OrderItem', 'dependent' => true, ) ); } if I switch the two and make OrderItem first, then that shows up in the scaffolding. What's the deal?? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Searching with multiple hasMany associations
I'm trying to create a flexible search form to search a database with multple hasMany associations. Here's the models: Part->hasMany->Mbmodel Part->hasMany->Signon Mbmodel->belongsTo->Part Signon->belongsTo->Part The Mbmodel table contains field model, Signon table contains signonstring. I'd like to be able to search by Mbmodels.model and Signon.signonstring to find results which only match those fields entered in search form. Basically, I'd like to implement CakePhP code which emulates the following SQL: SELECT * FROM parts, mbmodels, signons WHERE mbmodels.model LIKE '%M6TBA%' AND mbmodels.part_id = parts.id AND signons.signonstring LIKE '%2a69k%' AND signons.part_id = parts.id I've been able to implement code to search for Mbmodels.model: if (!empty($this->data['Mbmodel']['model'])) { $search_term = $this->data['Mbmodel']['model']; $conditions['Mbmodel']['model'] = "LIKE %{$search_term}%"; $parts = $this->Mbmodel->findAll($conditions); } Or to search for Signon.signonstring: if (!empty($this->data['Signon']['signonstring'])) { $search_term = $this->data['Signon']['signonstring']; $conditions['Signon']['signonstring'] = "LIKE %{$search_term}%"; $parts = $this->Signon->findAll($conditions); } Problem is I haven't been able to figure out how to implement something which supports both Mbmodel.model AND Signon.signonstring. Can anyone provide me some help? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Multiple hasMany / belongsTo
Oh, those are specific to my application. The transaction table in my database has "from" and "to" fields to help keep track of which user is the receiver and which user is the sender. Barton wrote: > Interesting, but what I don't get are the classNames "From' and 'To'. > What do you do with it? Did you create for 'From' and 'To' a model? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Multiple hasMany / belongsTo
Interesting, but what I don't get are the classNames "From' and 'To'. What do you do with it? Did you create for 'From' and 'To' a model? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Multiple hasMany / belongsTo
A-ha! I have no idea what I was thinking :) Thanks! It seems to be working properly now. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Multiple hasMany / belongsTo
What am I doing wrong? Are my hasMany/belongsTo statements wrong? I get no errors. It looks correct to me too (but I'm also quite new to CakePHP ;) ). Did you enable SQL debug output (in app/config/core.php) ? Did it try to generate the SQL for the associations, or did it not even try that ? Anselm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Multiple hasMany / belongsTo
hi your hasMany, belongsTo, and all associations definitions will work better if they are in your Model classes rather than in your Controller classes ! ++ clemos On 1/15/07, squidliberty <[EMAIL PROTECTED]> wrote: Hi, I am still pretty new to CakePHP and I am having trouble doing something relatively simple... I have a database of members and I need to record transactions between members. At its most simple, each transaction entry needs an amount, a sender id and a receiver id. So my database looks something like this: Table 'members' - id Table 'transactions' - id - member_to - member_from - amount It is important to differentiate between the sending member and the receiving member. I am new to hasMany, but I surmise that my controllers should look something like this: class MembersController extends AppController { var $name = 'Members'; var $hasMany = array('Credit' => array('className' => 'Transaction', 'conditions' => '', 'order' => '', 'limit' => '', 'foreignKey' => 'member_to', 'dependent' => false, 'exclusive' => false, 'finderQuery' => ''), 'Debit' => array('className' => 'Transaction', 'conditions' => '', 'order' => '', 'limit' => '', 'foreignKey' => 'member_from', 'dependent' => false, 'exclusive' => false, 'finderQuery' => '')); } class TransactionsController extends AppController { var $name = 'Transactions'; var $scaffold; var $belongsTo = array('From' => array('className' => 'Member', 'conditions' => '', 'order' => '', 'foreignKey' => 'member_from'), 'To' => array('className' => 'Member', 'conditions' => '', 'order' => '', 'foreignKey' => 'member_to')); } So, although this makes sense to me, when I load a member (using $this->Member->findById) and print out the array (using print_r()), I only see the 'Member' array... no 'Debit' or 'Credit' arrays... What am I doing wrong? Are my hasMany/belongsTo statements wrong? I get no errors. Thanks! > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Multiple hasMany / belongsTo
Hi, I am still pretty new to CakePHP and I am having trouble doing something relatively simple... I have a database of members and I need to record transactions between members. At its most simple, each transaction entry needs an amount, a sender id and a receiver id. So my database looks something like this: Table 'members' - id Table 'transactions' - id - member_to - member_from - amount It is important to differentiate between the sending member and the receiving member. I am new to hasMany, but I surmise that my controllers should look something like this: class MembersController extends AppController { var $name = 'Members'; var $hasMany = array('Credit' => array('className' => 'Transaction', 'conditions' => '', 'order' => '', 'limit' => '', 'foreignKey' => 'member_to', 'dependent' => false, 'exclusive' => false, 'finderQuery' => ''), 'Debit' => array('className' => 'Transaction', 'conditions' => '', 'order' => '', 'limit' => '', 'foreignKey' => 'member_from', 'dependent' => false, 'exclusive' => false, 'finderQuery' => '')); } class TransactionsController extends AppController { var $name = 'Transactions'; var $scaffold; var $belongsTo = array('From' => array('className' => 'Member', 'conditions' => '', 'order' => '', 'foreignKey' => 'member_from'), 'To' => array('className' => 'Member', 'conditions' => '', 'order' => '', 'foreignKey' => 'member_to')); } So, although this makes sense to me, when I load a member (using $this->Member->findById) and print out the array (using print_r()), I only see the 'Member' array... no 'Debit' or 'Credit' arrays... What am I doing wrong? Are my hasMany/belongsTo statements wrong? I get no errors. Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---