Re: Still having trouble with saving BelongsToMany data
Actually Joe, The listing does not save for me. I get the error that it couldn't save. Also, the debugger shows that the entities for the joint data have errors which say that the attribute_id and listing_id are required but not supplied. In that the attribute_id is known, it could be passed along with the joinData, but the listing_id is supposed to be being generated by the insert and it does not appear to be doing this. I will try tinkering with it a bit more, and if I don't see any progress, I will submit a bug report unless you would like to do that yourself. --Kevin -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: Still having trouble with saving BelongsToMany data
Also, just to clarify, i'm not adding new Attributes in the Listing form. i'm displaying them, and when the user checks them, a text input is shown for those that require it. The only data i need to save apart from the Listing is in ListingsAttributes: attribute_id : 1 (Attribute's checkbox value), listing_id : 1 (new id generated by Listings save), value: 'Off-street' (string from the checked Attribute's text input) But it sounds like you're hitting the same issue i am: the Listing record saves, but nothing is fed to ListingsAttributes despite the established associations. Thanks for at least investigating it further. i just wish i knew what to do about it. -joe On Sunday, 22 February 2015 17:39:52 UTC-5, heavyKevy wrote: > > I took the time to construct a test project with the 3 join tables and was > able to get data that looks like the documentation requires, but it refuses > to save. > The joint marshaller chokes because no listing_id, and no attribute_id is > found when marshalling the _joinData. > > I don't see in the documentation what else needs to be included to ensure > that the attributes are saved. > > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: Still having trouble with saving BelongsToMany data
Thanks for responding. So i might NOT be crazy??? The 3 you identified as the ID isn't - it's the array index for that listing field. See the inputs again. "Parking" is index 3, its record ID is 1. i wouldn't want to insert 3 as the *listings_attributes.attribute_id*. i re-baked the Tables, Entity, and Controller classes as you suggested. While there were some minor discrepancies i merged into the originals, it doesn't seem the re-bakes are working either. The chief difference in the controller: Original: // i've also tried a few variants of this, where either *nothing* gets saved, or *only* the Listing record. $listing = $this->Listings->newEntity($this->request->data, ['associated' => ['Attributes._joinData']]); Re-baked: $listing = $this->Listings->newEntity(); $listing = $this->Listings->patchEntity($listing, $this->request->data); Just as you reported, i can manage to save the Listings record under some variations, but never the ListingsAttributes record(s). i can't see anything in the documentation i'm skipping, either. Also as you mentioned, when i patch the Listing entity (or create it directly from request data), the association (attributes) data from request disappears. i was actually surprised by the docs update, which is why i came back to revisit this issue. Even with the updated documentation, i haven't managed to make the joint table data save. i suppose i'll have to force it in by creating a separate entity, but i don't think that's how the Cake magic is supposed to work... Thanks for following up, and (at least tentatively) confirming i'm not insane with this issue. ;-) -joe On Sunday, 22 February 2015 17:39:52 UTC-5, heavyKevy wrote: > > I took the time to construct a test project with the 3 join tables and was > able to get data that looks like the documentation requires, but it refuses > to save. > The joint marshaller chokes because no listing_id, and no attribute_id is > found when marshalling the _joinData. > > I don't see in the documentation what else needs to be included to ensure > that the attributes are saved. > > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: Still having trouble with saving BelongsToMany data
I took the time to construct a test project with the 3 join tables and was able to get data that looks like the documentation requires, but it refuses to save. The joint marshaller chokes because no listing_id, and no attribute_id is found when marshalling the _joinData. I don't see in the documentation what else needs to be included to ensure that the attributes are saved. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
pagination with join and array in cakephp
Hi, in cakephp I used a 'find all' to do a complex and this works fine as below. My issue is I am trying to convert this to a set paginated results and I keep getting offset warning Illegal offset type [CORE\Cake\Model\Model.php, line 2936. I am sure the issue is simple but is there a way to to do this with the $option arrays I have for the search . I didnt see an example in the docs for the paginate results with an array set for the options http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html $this->Lesson->recursive = -1; $options['joins'] = array( array('table' => 'lessons_students', 'alias' => 'LessonsStudent', 'type' => 'LEFT', 'conditions' => array( 'Lesson.id = LessonsStudent.lesson_id', ) ), array('table' => 'students', 'alias' => 'Student', 'type' => 'LEFT', 'conditions' => array( 'LessonsStudent.student_id=Student.id', ) ), array('table' => 'subjects', 'alias' => 'Subject', 'type' => 'LEFT', 'conditions' => array( 'Lesson.subject_id=Subject.id', ) ), array( 'table' => 'tutors', 'alias' => 'Tutor', 'type' => 'LEFT', 'conditions' => array( 'Lesson.tutor_id = Tutor.id' ) ) , array('table' => 'tutoring_types', 'alias' => 'TutoringType', 'type' => 'LEFT', 'conditions' => array( 'Lesson.tutoring_type_id=TutoringType.id', ) ) ); $options['fields'] = array('Student.last_name','Student.first_name','Student.id', 'Lesson.lesson_date', 'Lesson.start_time', 'Lesson.end_time', 'Lesson.id','Lesson.schedule_rec','Lesson.schedule_monthly','Lesson.schedule_yearly', 'Lesson.cancelled_by', 'Lesson.makeup_lesson', 'Lesson.tutoring_type_id', 'Lesson.forefit', 'LessonsStudent.*', 'Tutor.last_name', 'Tutor.first_name','Tutor.id', 'Subject.name','Subject.id', 'TutoringType.*'); $options['conditions'] = array('Lesson.lesson_inactive' => 0,'Lesson.makeup_lesson' => 0,'Lesson.forefit' => 0, 'Lesson.lesson_date >= ' => $startdate, 'Lesson.lesson_date <= ' => $enddate, 'AND' =>array( array('OR' => array( array('Student.first_name LIKE' => '%' . $searchFirstName . '%'), array('Tutor.first_name LIKE' => '%' . $searchFirstName . '%'), array('Student.guardian_first_name LIKE' => '%' . $searchFirstName . '%'), ), array('OR' => array( array('Student.last_name LIKE' => '%' . $searchLastName . '%'), array('Tutor.last_name LIKE' => '%' . $searchLastName . '%'), array('Student.guardian_last_name LIKE' => '%' . $searchLastName . '%'), ) , array('OR' => array( array('Student.student_mobile LIKE' => '%' . $searchmobile . '%'), array('Tutor.mobile LIKE' => '%' . $searchmobile . '%'), array('Student.guardian_mobile LIKE' => '%' . $searchmobile . '%'), ) ); $options['order'] =array('Lesson.lesson_date','Lesson.start_time'); $options['limit'] =150; $options['page'] =1; //$lessons= $this->Lesson->find('all', $options ); $options['recursive'] =50; $this->Paginator->settings = array($options); $lessons= $this->Paginator->paginate('Lesson'); -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You rec
Re: Still having trouble with saving BelongsToMany data
If Listings is the table being saved, having attributes, then there seems to be something wrong with your data. I believe that your data should look like the following: $data = [ 'attributes' => [ [ 'id' => 3, //provided the id is already known '_joinData' => [ 'value' => 'Off-street' ] ], ] ]; $listing = $this->Listings->newEntity($data, [ 'associated' => ['Attributes._joinData'] ]); Question: Did you try baking the models, making sure the associations were all correct as as you expected, then bake the controllers and views? It seems that the bake utility should generate the code for doing this. --Kevin -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.