LemonStand Forum: Problem saving Db_ActiveRecord rows - LemonStand Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Problem saving Db_ActiveRecord rows

#1 User is offline   paulbennett 

  • Member
  • Group: Members
  • Posts: 4
  • Joined: 04-January 12

Posted 04 January 2012 - 01:52 AM

Hi all, I'm building an auction module but am having some problems saving rows to the database.

In this snippet $max_bid is a ReddotAuction_Maxbid object which extends Db_ActiveRecord, and I'm checking to see if the new bid was made by the current winning bidder - if it is row just needs to be updated with their new maximum bid.

$amount is the new bid amount, and $user is a Shop_Customer object.

...

// Is the new bid from the current high bidder?
elseif ($user->id == $max_bid->user_id)
{
	if ($amount > $max_bid->amount)
	{
		$max_bid->amount = $amount;
		$max_bid->save(); // FIXME doesn't save

		return ReddotAuction_Bid::STATE_RAISED;				
	}
	else
	{
		return ReddotAuction_Bid::STATE_NOT_ENOUGH;	
	}
}

...


The snippet works correctly and returns the expected state, however the row isn't saved to the database, am I doing something wrong?

Thanks!
0

#2 User is offline   Eric 

  • Developer
  • PipPipPip
  • Group: Members
  • Posts: 1,290
  • Joined: 04-August 10
  • LocationVancouver, Canada

Posted 04 January 2012 - 10:32 AM

Hi Paul,

Hmm. Perhaps it's saved but the AR object does not get updated automatically? In which case you'll need to recreate it with: $max_bid = ReddotAuction_Maxbid::create()->find($max_bid->id).

You've confirmed in the DB it's not being saved? But it's being created fine? Can you show the creation of the $max_bid object? Can you try creating a basic one in a page to see if it works?

$max_bid = ReddotAuction_Maxbid::create();
$max_bid->amount = 5;
$max_bid->save()


Thanks
0

#3 User is offline   paulbennett 

  • Member
  • Group: Members
  • Posts: 4
  • Joined: 04-January 12

Posted 07 January 2012 - 07:37 AM

Hi Eric, it was my fault - turns out $max_bid wasn't actually a row object :( I fixed that and now save() works as expected!
0

Share this topic:


Page 1 of 1

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users