All,
Many thanks for the previous help I have received from this list ... I am hoping someone can point me in the right direction here. I am attempting to bolt on a ROR admin system for an existing oscommerce store, and so far have been fairly successful.
My setup is a basic oscommerce install, which is apache/php/mysql. I have abbreviated the tables to include only information relevant to my issue.
Database Tables in question customers: customers_id int(11) NOT NULL auto_increment, customers_firstname varchar(32) NOT NULL, customers_default_address_id int(11) default NULL, PRIMARY KEY (customers_id)
Example row in customers: customers_id = 50 customers_firstname = bob customers_default_address_id = 1
address_book: address_book_id int(11) NOT NULL auto_increment, customers_id int(11) NOT NULL, entry_firstname varchar(32) NOT NULL, entry_postcode varchar(10) NOT NULL, entry_state varchar(32) default NULL, entry_country_id int(11) NOT NULL default '0', entry_zone_id int(11) NOT NULL default '0', PRIMARY KEY (address_book_id),
Example rows in the address_book table: address_book_id = 1 customers_id = 50 entry_firstname = bob entry_postcode = 45619 entry_state = Alaska entry_country_id = 223 entry_zone_id = 2
address_book_id = 11 customers_id = 50 entry_firstname = bob entry_postcode = 40000 entry_state = Alaska entry_country_id = 223 entry_zone_id = 2
zones: zone_id int(11) NOT NULL auto_increment, zone_country_id int(11) NOT NULL, zone_code varchar(32) NOT NULL, zone_name varchar(32) NOT NULL, PRIMARY KEY (zone_id), KEY idx_zones_country_id (zone_country_id)
Example row in the zones table: zone_id = 2 zone_country_id = 223 (this is the US) zone_code = AK zone_name = Alaska
The customers table has the name/email/basic information for a customer. The address_book table (note the non plural table name) contains multiple mailing/shipping addresses for a customer. The customers_default_address_id in the customers table denotes which is the default address to ship to. In my example, bob has two addresses in Alaska.
My issue is, how can I represent this information in a collection of models such that I can use the address information properly.
My existing customer model works just fine. I attempted to add an "address_book" model, but ran into some trouble with the non-plural table name plus the fact that it had an underscore. The fact that the state two letter abbreviation is actually stored in the zones table, left me a little stuck.
My goal was to be able to do something like this:
c = Customer.find 50 - this would find the customer record for bob - this works great. c.customers_state would return the current state of the current default address (the two letter, requiring a hit of the address_book and zones table). c.addressbooks would return a list of all the addresses for a customer.
My existing solution to this problem was to create a view in mysql for my customer information and have it only use the current default address. This was going to be an OK solution, but I discovered the hosting service for my site is using a downlevel version of mysql, and views are not possible.
I would be glad to share my completed mapping of rails to oscommerce when I am done if anyone is interested ...
Note: I am still a newbie on rails - please tell me if this is the not the right place for this question. Thanks for any help anyone can provide.
Dustin