I am saving a Rate record and an associated image using the Media
plugin (https://github.com/davidpersson/media). Everything works fine
when an image is added, when an image isn't added the Rate record gets
corrupted.
Thanks for taking the time to reply @jeremyharris. The record is still
getting written but the 'Rate' data is missing. The following is an
example of a saved record. As you can see the 'Rate' data is missing.
What behaviors are you using besides Transfer? Coupler tends to mess with the data because it expects *just* the fields in the Media.Attachment model. Try removing Coupler if it's attached (since you're not using it).
Also, unit tests are your friend. It would be much easier to try things and debug using unit tests rather than not.
Thanks for your reply. Okay, sounds like it could be related to the
Coupler then. I tried removing the Coupler and the 'Rate' data is then
saving correctly but the image is missing. I am using 'dirname' and
'basename' fields in the 'Rate' table rather than using a separate
Attachment table, does this mean I don't need the Coupler element?
On Feb 24, 2:19 am, jeremyharris <funeralm...@gmail.com> wrote:
> What behaviors are you using besides Transfer? Coupler tends to mess with
> the data because it expects *just* the fields in the Media.Attachment
> model. Try removing Coupler if it's attached (since you're not using it).
> Also, unit tests are your friend. It would be much easier to try things and
> debug using unit tests rather than not.
Okay I think I misspoke. You do need the coupler. (Sorry lack of docs and it's been a while since I had to configure.)
I'd stick some debug statements through all of the behaviors' beforeSave calls to try and figure out what's happening. I'm suspicious that the rate data is being removed in Coupler's beforeSave due to some issue with the 'file' key not being there or not being validated. This will hopefully give you a better understanding of what's going on.
On Friday, February 24, 2012 1:02:05 AM UTC-8, Kro wrote:
> Thanks for your reply. Okay, sounds like it could be related to the > Coupler then. I tried removing the Coupler and the 'Rate' data is then > saving correctly but the image is missing. I am using 'dirname' and > 'basename' fields in the 'Rate' table rather than using a separate > Attachment table, does this mean I don't need the Coupler element?
> On Feb 24, 2:19 am, jeremyharris <funeralm...@gmail.com> wrote: > > What behaviors are you using besides Transfer? Coupler tends to mess > with > > the data because it expects *just* the fields in the Media.Attachment > > model. Try removing Coupler if it's attached (since you're not using > it).
> > Also, unit tests are your friend. It would be much easier to try things > and > > debug using unit tests rather than not.
Thank you so much, it's working now! You were spot on, it was the
Couplers beforesave that was unsetting the data. I have stopped it
doing that now and I can't see why that would cause any other issues.
The change I have made is as follows:
function beforeSave(&$Model) {
if (!$Model->exists()) {
if (!isset($Model->data[$Model->alias]['file'])) {
removed unset ---> //unset($Model->data[$Model-
> Okay I think I misspoke. You do need the coupler. (Sorry lack of docs and
> it's been a while since I had to configure.)
> I'd stick some debug statements through all of the behaviors' beforeSave
> calls to try and figure out what's happening. I'm suspicious that the rate
> data is being removed in Coupler's beforeSave due to some issue with the
> 'file' key not being there or not being validated. This will hopefully give
> you a better understanding of what's going on.
> On Friday, February 24, 2012 1:02:05 AM UTC-8, Kro wrote:
> > Thanks for your reply. Okay, sounds like it could be related to the
> > Coupler then. I tried removing the Coupler and the 'Rate' data is then
> > saving correctly but the image is missing. I am using 'dirname' and
> > 'basename' fields in the 'Rate' table rather than using a separate
> > Attachment table, does this mean I don't need the Coupler element?
> > On Feb 24, 2:19 am, jeremyharris <funeralm...@gmail.com> wrote:
> > > What behaviors are you using besides Transfer? Coupler tends to mess
> > with
> > > the data because it expects *just* the fields in the Media.Attachment
> > > model. Try removing Coupler if it's attached (since you're not using
> > it).
> > > Also, unit tests are your friend. It would be much easier to try things
> > and
> > > debug using unit tests rather than not.
On Saturday, February 25, 2012 10:48:59 AM UTC-8, Kro wrote:
> Thank you so much, it's working now! You were spot on, it was the > Couplers beforesave that was unsetting the data. I have stopped it > doing that now and I can't see why that would cause any other issues.
> The change I have made is as follows: > function beforeSave(&$Model) { > if (!$Model->exists()) { > if (!isset($Model->data[$Model->alias]['file'])) { > removed unset ---> > //unset($Model->data[$Model- > >alias]); > return true; > } > } else { > if (isset($Model->data[$Model->alias]['delete']) > && $Model->data[$Model->alias]['delete'] !== '0') > { > $Model->delete(); > unset($Model->data[$Model->alias]); > return true; > } > }
> Thanks again...
> On Feb 24, 5:48 pm, jeremyharris <funeralm...@gmail.com> wrote: > > Okay I think I misspoke. You do need the coupler. (Sorry lack of docs > and > > it's been a while since I had to configure.)
> > I'd stick some debug statements through all of the behaviors' beforeSave > > calls to try and figure out what's happening. I'm suspicious that the > rate > > data is being removed in Coupler's beforeSave due to some issue with the > > 'file' key not being there or not being validated. This will hopefully > give > > you a better understanding of what's going on.
> > On Friday, February 24, 2012 1:02:05 AM UTC-8, Kro wrote:
> > > Thanks for your reply. Okay, sounds like it could be related to the > > > Coupler then. I tried removing the Coupler and the 'Rate' data is then > > > saving correctly but the image is missing. I am using 'dirname' and > > > 'basename' fields in the 'Rate' table rather than using a separate > > > Attachment table, does this mean I don't need the Coupler element?
> > > On Feb 24, 2:19 am, jeremyharris <funeralm...@gmail.com> wrote: > > > > What behaviors are you using besides Transfer? Coupler tends to mess > > > with > > > > the data because it expects *just* the fields in the > Media.Attachment > > > > model. Try removing Coupler if it's attached (since you're not using > > > it).
> > > > Also, unit tests are your friend. It would be much easier to try > things > > > and > > > > debug using unit tests rather than not.
> On Saturday, February 25, 2012 10:48:59 AM UTC-8, Kro wrote:
> > Thank you so much, it's working now! You were spot on, it was the
> > Couplers beforesave that was unsetting the data. I have stopped it
> > doing that now and I can't see why that would cause any other issues.
> > The change I have made is as follows:
> > function beforeSave(&$Model) {
> > if (!$Model->exists()) {
> > if (!isset($Model->data[$Model->alias]['file'])) {
> > removed unset --->
> > //unset($Model->data[$Model-
> > >alias]);
> > return true;
> > }
> > } else {
> > if (isset($Model->data[$Model->alias]['delete'])
> > && $Model->data[$Model->alias]['delete'] !== '0')
> > {
> > $Model->delete();
> > unset($Model->data[$Model->alias]);
> > return true;
> > }
> > }
> > Thanks again...
> > On Feb 24, 5:48 pm, jeremyharris <funeralm...@gmail.com> wrote:
> > > Okay I think I misspoke. You do need the coupler. (Sorry lack of docs
> > and
> > > it's been a while since I had to configure.)
> > > I'd stick some debug statements through all of the behaviors' beforeSave
> > > calls to try and figure out what's happening. I'm suspicious that the
> > rate
> > > data is being removed in Coupler's beforeSave due to some issue with the
> > > 'file' key not being there or not being validated. This will hopefully
> > give
> > > you a better understanding of what's going on.
> > > On Friday, February 24, 2012 1:02:05 AM UTC-8, Kro wrote:
> > > > Thanks for your reply. Okay, sounds like it could be related to the
> > > > Coupler then. I tried removing the Coupler and the 'Rate' data is then
> > > > saving correctly but the image is missing. I am using 'dirname' and
> > > > 'basename' fields in the 'Rate' table rather than using a separate
> > > > Attachment table, does this mean I don't need the Coupler element?
> > > > On Feb 24, 2:19 am, jeremyharris <funeralm...@gmail.com> wrote:
> > > > > What behaviors are you using besides Transfer? Coupler tends to mess
> > > > with
> > > > > the data because it expects *just* the fields in the
> > Media.Attachment
> > > > > model. Try removing Coupler if it's attached (since you're not using
> > > > it).
> > > > > Also, unit tests are your friend. It would be much easier to try
> > things
> > > > and
> > > > > debug using unit tests rather than not.