[Ruby] Associations problem
shaners becker
veganstraightedge at gmail.com
Sat Jan 6 02:08:12 PST 2007
i describe my app/db setup first, then my question is at the bottom.
i building an app for comic shops. they have customers that have a
subscription. meaning every month when the new x-men (let's say)
comes out a copy gets put in their box even if they're not around on
that day. that way they don't have to worry about it selling out
before they get there.
so i have three tables: subscribers, subscription_items and products
subscriber has_many subscription_items
subscription_item has_many products
products belongs_to subscription_item
subscription_items belongs_to subscriber
subscribers':
box_number
first_name
last_name
email
phone
street_address
city
state
zipcode
created_at
updated_at
last_purchase
notes
subscription_items' schema:
subscriber_id
product_id
created_at
updated_at
start_issue
end_issue
notes
products' schema:
diamond_item_code
title
description
retail_price
publisher
genre
upc
in the console:
l = Subscriber.find 1
=>
--- !ruby/object:Subscriber
attributes:
city: sea
box_number: "73"
updated_at:
zipcode: "98105"
notes: he only comes in every few months, but is good about
clearing out his box.
id: "1"
street_address: 4733 roosevelt way
phone: 801-898-9481
first_name: shane
last_name: becker
last_purchase: 2007-01-03 06:09:03
created_at: 2006-09-18 16:09:03
state: wa
email: veganstraightedge at gmail.com
>> y l.subscription_items
---
- !ruby/object:SubscriptionItem
attributes:
updated_at: 2007-01-06 01:41:11
product_id: "4999"
notes: only the grant morrison stuff
id: "1"
start_issue: "4"
subscriber_id: "1"
end_issue: "74"
created_at: 2007-01-06 01:38:01
- !ruby/object:SubscriptionItem
attributes:
updated_at: 2007-01-06 01:41:11
product_id: "6732"
notes: ""
id: "2"
start_issue: "1"
subscriber_id: "1"
end_issue: "7"
created_at: 2007-01-06 01:38:01
if a Product object looks like this:
title: SPIDER-MAN KEYCHAIN GACHA CAPSULE TOY ASST (APR045096)
diamond_item_code: DEC060093J3
id: "4999"
publisher: DARK HORSE COMICS
retail_price: "0"
description:
genre: SH
upc: "1"
************************************************************************
*****
************************************************************************
*****
how do i refer to the title of a subscription_item of this user?
is this a case for habtm or through?
************************************************************************
*****
************************************************************************
*****
sorry this one was so long. i figured i needed to explain my setup
first.
thanks in advance for any help.
shane
------------------------------------
first things first. next things next.
http://theresistancearmy.com/blog/
------------------------------------
More information about the Ruby
mailing list