seems to work. I still have this feeling that there is a better way
to do this...I feel like I'm breaking the whole purpose of having
models. Comments welcome.
if($this->data['Price']['prime'] == 1)
{ // update the prime
$this->loadModel('Part', $this->data['Price']['part_id']);
$this->Part->read();
$this->Part->set('prime_price_id', $this->Price->getLastInsertId());
$this->Part->save($this->data);
}
On May 29, 1:55 pm, turbo2ltr <turbo2...@gmail.com> wrote:
> Yeah that doesn't work either.
>
> As far as I can tell, my associations work.
>
> Part model:
> var $belongsTo = array('price'=>array('classname' => 'Price',
> 'foreignKey' => 'prime_price_id') );
> var $hasMany = array('Price' => array( 'className' => 'Price'));
>
> A part will have a lot of prices.
> Part has a field for a price ID (which defines the default price)
>
> I already have the ability to add/edit a price to a part. If someone
> fills out the price form and submits it, it works fine, but if they
> check the "prime" box, I want to get the ID of the newly added/updated
> price and update the Part's prime_price_id field for the part. But I
> have to handle this from the price controller, not the part controller
>
> Am I overthinking this? I can think of 100 hackish ways to do this,
> but I assumed there would be a correct/ cakish way to do this. At
> this point it would be worth my money to pay a cake expert to help
> me...anyone looking for some beer money?
>
> On May 15, 12:21 pm, Jeremy Burns | Class Outfit
>
> <jeremybu...@classoutfit.com> wrote:
> > Actually, just read this again. In the prices controller you have to call $this->Price->Part to reach parts, or just $this->Price to reach prices.
>
> > Jeremy Burns
> > Class Outfit
>
> > jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> > On 15 May 2011, at 17:09,turbo2ltrwrote:
>
> > > Well that's the first thing I tried and I couldn't get it to work.
>
> > > If I try to use any reference like '$this->Part->Price' from the
> > > Prices controller I get:
> > > Undefined property: PricesController::$Part [APP/controllers/
> > > prices_controller.php, line 52]
>
> > > On May 15, 5:48 am, euromark <dereurom...@googlemail.com> wrote:
> > >> despite the fact that your code doesnt really look too cakish
> > >> the correct approach to access related models is through chaining:
>
> > >> $this->Part->Price->foo();
>
> > >> On 15 Mai, 06:43,turbo2ltr<turbo2...@gmail.com> wrote:
>
> > >>> Parts hasMany Prices.
> > >>> Parts belongsTo Prices
>
> > >>> The idea is a part can have many prices but Part will have one Price
> > >>> ID that will indicate the default price.
>
> > >>> In the Prices controller, how would I go about updating the Parts
> > >>> field? I searched around and it seems to be a common problem, but the
> > >>> answers didn't get me anywhere.
>
> > >>> One of my attempts that doesn't work.. this code is if the Price Add
> > >>> form is submitted and the user indicated it was the default (prime):
>
> > >>> $this->Part->id = $this->data['Price']['part_id'];
> > >>> $partdata = $this->Part->read();
> > >>> $partdata['Part']['prime_price_id'] = $this->Price->getLastInsertId();
> > >>> $this->Part->save($this->data);
>
> > > --
> > > Our newest site for the community: CakePHP Video Tutorialshttp://tv.cakephp.org
> > > Check out the new CakePHP Questions sitehttp://ask.cakephp.organdhelp others with their CakePHP related questions.
>
> > > To unsubscribe from this group, send email to
> > > cake-php+unsubscribe@googlegroups.com For more options, visit this group athttp://groups.google.com/group/cake-php
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
No comments:
Post a Comment