Auction associations and methods

hello... I'm trying to start an auction site and I need some help with the modeling of auctions and bids.

Would it be better to have auctions have many bids and bids belong to auctions, or Auction has one bid, bid belongs to auction?

Also, how would I call the bid object on the auction to change the :current_price attribute on auction, increment info it up by 1 dollar? Thanks for your help.

hello... I'm trying to start an auction site and I need some help with the modeling of auctions and bids.

Would it be better to have auctions have many bids and bids belong to auctions, or Auction has one bid, bid belongs to auction?

What does an Auction object represent? It may help to tell us some of the attributes of Auction to give us a better understanding. Having answered that the question is how many bids are associated with an auction? If the answer is many then it you must use auction has many bids, otherwise it would only be able to be associated with one bid.

Also, how would I call the bid object on the auction to change the :current_price attribute on auction, increment info it up by 1 dollar? Thanks for your help.

Is the current price the highest of the prices in the bids? In which case you should probably not store the current price at all, but work it out when needed from the associated bids. Only have it stored separately if it becomes a performance issue as it will likely complicate the code significantly.

Colin

Well the auction object needs to be the auction itself, where users join and bid... If my reasoning is flawed I would love some ideas.

As for the bidding, I was thinking that instead of there being a highest bidder, I would simply have a button that the users could click that would increase the price by one dollar every time. Is there a way I could do this? Clay

Are you just thinking of keeping track of the current price and which user it is then? I think there may be a problem with that, I think you will need to track the history of all bids in case there is a dispute from a user. Without the full history you would not be able to demonstrate the sequence of +1s

Also what would happen if 500 users all clicked the +$1 within a second of each other? The last one could end up having made a bid $499 more than he anticipated.

Colin

Exactly. These are some problems I haven't figured out how to solve! This is my first web application. I have thought about all users clicking at the same time... What would be a good way to keep track of the users, have a record of the bidding, and increment the price the same amount every time? Would it be a method in the model or controller or what?

Please quote the previous message when replying and insert your comments at appropriate points, it makes it easier to follow the thread. Otherwise someone seeing your previous message will have no idea what you are saying 'exactly' to. Thanks.

Don't worry about where methods go yet, get the models and associations sorted. It seems to me you are going to have to have auctions, users, bids with appropriate associations. The +1 button should not show +1 but show the new bid amount (current + 1) and that value should be posted when he clicks, so there is no confusion over the amount he is bidding. By keeping all the bids in the database then you have a history of what happened.

You will need something like user has many bids auction has many bids bid belongs to user bid belongs to auction

Colin

Exactly. These are some problems I haven’t figured out how to solve! This is my first web application. I have thought about all users clicking at the same time… What would be a good way to keep track of the users, have a record of the bidding, and increment the price the same amount every time? Would it be a method in the model or controller or what?

Please quote the previous message when replying and insert your

comments at appropriate points, it makes it easier to follow the

thread. Otherwise someone seeing your previous message will have no

idea what you are saying ‘exactly’ to. Thanks.

Ok sorry, im learning :slight_smile: this is my first post here.

Don’t worry about where methods go yet, get the models and

associations sorted. It seems to me you are going to have to have

auctions, users, bids with appropriate associations. The +1 button

should not show +1 but show the new bid amount (current + 1) and that

value should be posted when he clicks, so there is no confusion over

the amount he is bidding. By keeping all the bids in the database

then you have a history of what happened.

Ok! yes that makes sense. that way my users wont be confused or the system hopefully wont be broken if there is a lot of activity at the same time.

You will need something like

user has many bids

auction has many bids

bid belongs to user

bid belongs to auction

Colin

Alrighty. That is what I thought i would need to do for the associations. Thanks for your help Colin, I will do some more reading on those associations in the Rails Guides. I will need help with the methods once I have that established, if you dont mind. Thanks for your time. Clay

Can I check that you have already worked right through a good tutorial such as railstutorial.org (including doing the exercises and so on). If not then I highly recommend doing so, it will save you (and us) time in the long run.

Colin

No I did not finish that... I will try to finish it and if I have any more questions, I will let you know. Thanks Colin!