开发者

Modeling Buyers & Sellers in a Rails Ecommerce App

I'm building a Rails app that has Etsy.com style functionality. In other words, it's like a mall. There are many buyers and many sellers.

I'm torn about how to model the sellers. Key facts:

  • There won't be many sellers. Perhaps less than 20 sellers in total.
  • There will be many buyers. Hopefully many thousands :)
  • I already have a standard user model in place with account creation and roles.
  • I've created a 'role' of 'selle开发者_如何学JAVAr', which the admin will manually apply to the proper users. Since we'll have very few sellers, this is not an issue.

I'm considering two approaches:

(1) Create a 'store' model, which will contain all the relevant store information. Products would :belong_to :store, rather than belonging to the seller. The relationship between the user and store models would be: user :has_one store. My main problem with this is that I've always found has_one associations to be a little funky, and I usually try to avoid them. The app is fairly complex, and I'm worried about running into a cascade of problems connected to the has_one association as I get further along into development.

(2) Simply include the relevant 'store' information as part of the user model. But in this case, the store-related db columns would only apply to a very small percentage of users since very few users will also be sellers. I'm not sure if this is a valid concern or not.

It's very possible that I'm thinking about this incorrectly. I appreciate any thoughts.

Thanks.


I would definitely use a relationship between a store and a user. This provides a lot more flexibility and is a much cleaner data design.

I have never had any issues using any of the basic associations in Rails/Active Record. What do you mean by "funky"?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜