Nested models help (which methods to use?)

2012-09-07 Thread scotth25
Hello. I am looking for a simple solution for binding model to another model. I'm using CakePHP 2.2. I am building a JSON rest api. I currently have a simple User model with a hasOne Profile association. I want to nest the "Profile" model in the Users array, without using any views. What is th

Saving Nested Models

2012-04-04 Thread GoneShootin
This problem is beating me into a pulp, and if I could solve it I'd really be making headway on my app. Currently I have working the following type of relationship Contact "belongsTo" Location Location "hasMany" Contact ie - contacts.location_id = locations.id This works for all CRUD operations

Can't Get Media Plugin to Work with Nested Models

2011-10-03 Thread Mark
I have been using the Media Plugin by David Persson and I think it's great and has saved me a lot of time. I started out with an Invoice model that hasMany Attachments and everything worked well. I then added Materials to my invoice and tried added Attachments to a specific material associated wi

Re: Find condition on nested models

2010-05-05 Thread John Andersen
What is your recursive parameter set to? And have you considered using Containable behaviour? See http://book.cakephp.org/view/474/Containable Enjoy, John On May 5, 4:54 pm, Greg Skerman wrote: > Hey guys, > > Struggling to figure out why this wont work (cake 1.2). > >         $this->set('Ch

Find condition on nested models

2010-05-05 Thread Greg Skerman
Hey guys, Struggling to figure out why this wont work (cake 1.2). $this->set('Characters', $this->User->Account->Character->find('list', array( 'conditions' => array( 'User.id' => $this->Auth->User('id') ) )

Re: Nested Models

2009-12-29 Thread Walther
You could do http://www.application.com/message/add/contract:1 using named parameters. Or setup a route for www.application.com/contract/1/message/add On Dec 28, 11:09 pm, otisjs01 wrote: > OK, so I'm asking lots of questions today...but I really want to > learn! :) > > Anyway, I'm trying to cre

Re: Nested Models

2009-12-28 Thread John Andersen
When a user selects a contract to view, store the contract id internally (session). Then when the user requests to view the related messages, show the messages and add a form for the user to enter a new message, and have the form url be /messages/add. If the user adds a new message, retrieve the c

Re: find() when having nested models

2009-10-01 Thread John Andersen
No problem :) On Oct 1, 6:00 pm, Melanie Sommer wrote: > Problem solved. There was a typing error in the C model. Sorry! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send e

Re: find() when having nested models

2009-10-01 Thread Melanie Sommer
Problem solved. There was a typing error in the C model. Sorry! --~--~-~--~~~---~--~~ 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

Re: find() when having nested models

2009-10-01 Thread Melanie Sommer
Hello John, I already tried putting all X.id and X.Y_id in the respective field arrays - no change. And this also does not explain, why cakephp does the right thing automatically when I select B, C, D, F, and G, but not when selecting A. What I do not understand is the difference between the beh

Re: find() when having nested models

2009-10-01 Thread John Andersen
Yes, I read that too, and later in the text is this note: "When using 'fields' and 'contain' options - be careful to include all foreign keys that your query directly or indirectly requires." And to me it looks like you should ensure that you specify the primary keys (id) and the foreign keys (c

Re: find() when having nested models

2009-10-01 Thread Melanie Sommer
Hi John, > I think I read somewhere (here in the group) that you need to include > the foreign keys in the fields definition, so containable can see > them! I read contain automatically also includes the foreign keys in it's sql-query. http://book.cakephp.org/view/474/Containable : "As you can se

Re: find() when having nested models

2009-10-01 Thread John Andersen
I think I read somewhere (here in the group) that you need to include the foreign keys in the fields definition, so containable can see them! Enjoy, John On Oct 1, 1:51 pm, Melanie Sommer wrote: > Hello Brian, > > thank you for the information about containable. It works fine, except > for on

Re: find() when having nested models

2009-10-01 Thread Melanie Sommer
Hello Brian, thank you for the information about containable. It works fine, except for one problem. I use this code: > $this->E->find( > 'all', > array( > 'contain' => array( > 'D' => array( > 'fields' => array('D.tit

Re: find() when having nested models

2009-09-29 Thread brian
Use ContainableBehavior and try the find() like: $this->E->find( 'all', array( 'contain' => array( 'D' => array( 'fields' => array('D.title'), 'C' => array(

find() when having nested models

2009-09-29 Thread Melanie Sommer
Hi, I have models with belongsTo and hasMany relations in the following form: A -> C -> D -> E B -> C F -> E G -> E When displaying E I also want to display the title-fields of A, B, C, D, F and G. find() can only be set to rescursive=2 giving me E together with D, C, F, G. What is the best wa

Re: Specifying fields in nested models

2009-07-23 Thread toby1kenobi
> > the most deeply nested ParentContentItem shows different content, it > gets the data corresponding to the instance with id = 1 (rather than 2 > in the example above). > >   Can anyone see where I'm going wrong? > >   Thanks, > > Toby > > On

Re: Specifying fields in nested models

2009-07-23 Thread toby1kenobi
am, toby1kenobi wrote: > Aha, found it! I needed the ContainableBehaviour. In case it helps > someone else I found this (in addition to the manual) very helpful: > > http://teknoid.wordpress.com/2008/09/05/example-of-cakephps-containab... > > toby1kenobi wrote: > > Hi all,

Re: Specifying fields in nested models

2009-07-23 Thread toby1kenobi
w if it's possible to specify which fields are > returned in a call to paginate, including fields from nested models. > Something like: > > $this->paginate['MyModel']['fields'] = array( > 'DISTINCT MyModel.id, MyModel.title

Specifying fields in nested models

2009-07-22 Thread toby1kenobi
Hi all, Does anyone know if it's possible to specify which fields are returned in a call to paginate, including fields from nested models. Something like: $this->paginate['MyModel']['fields'] = array( 'DISTINCT MyModel.id, MyModel.title,

SaveAll() with nested Models

2008-12-28 Thread Fi
Hello, SaveAll works great with the examples provided in the docs and through the majority of blogs. My Problem is that I want to Save three nested Models at once. Currently I do this with the help of transactions and some awkward validation. For example I have these Models: Test has many

Re: nested models

2008-01-16 Thread manish
http://tempdocs.cakephp.org/#TOC78863 On Jan 17, 7:09 am, Carl <[EMAIL PROTECTED]> wrote: > I have a table of headings and a table of categories. Each heading > "hasMany" categories, and each category "belongsTo" a heading. I need > a view that lists each heading with its associated categories. >

Re: nested models

2008-01-16 Thread Sam Sherlock
As I recall from a recording of a cakeshow that 1.2 automagically handles this is you create a camelized var from the model name and pass that findall eg in post controller (in this example I have changed categories to post_categories) $postCategories = $this-postCategories->findAll(...) $this->

nested models

2008-01-16 Thread Carl
I have a table of headings and a table of categories. Each heading "hasMany" categories, and each category "belongsTo" a heading. I need a view that lists each heading with its associated categories. I have the models working with the "scaffolded" views of headings and categories (separately), bu