Jon
2006-Jun-30 06:39 UTC
[Rails] Help with translating an object model to a relational mode
Hello rails friends,
I am writing a soap interface to a databse for a .Net guy in rails.
Actionwebservice kicks ass, however, I need some help translating the
object model to a relational one:
class Customer{
string firstName
#blah
string[] email_addresses
PurchaseHistory[] myPurchases
}
class PurchaseHistory{
#blah blah blah
}
The object model is non-negotiable. I am not allowed to change it, I
have to create
equivalent soap objects for his types.
The problem comes with the arrays. How do I store those in the
database?
Here is the migration I''ve wrote so far:
class CreateCustomers < ActiveRecord::Migration
def self.up
create_table :customers do |t|
t.column :firstName, :string
#blah
t.column : email_addresses, [:string] # This does not work.
Migrate freaks out! help!
# purchase history array???? help!
end
end
def self.down
drop_table :customers
end
Migrate says this when i try to migrate that:
== CreateCustomers: migrating
================================================-- create_table(:customers)
rake aborted!
undefined method `to_sym'' for [:string]:Array
So my questions are:
1. What is the proper way to do this?
=>How do I store an array in the database?
=>How do I tell activerecord to create a column for an array?
Please do not reply "your object model is poor" because that is out of
my control.
Thank you for your time and your help! I really appreciate the ROR
community and the time they take promoting their framework. I guess when
you help a noob like me, then eventually I get good at ROR and will be
able reach out eventually and help other noobs.
--
Posted via http://www.ruby-forum.com/.
Jon
2006-Jun-30 16:51 UTC
[Rails] Re: Help with translating an object model to a relational mo
Someone Please... -- Posted via http://www.ruby-forum.com/.
Bill Walton
2006-Jun-30 17:08 UTC
[Rails] Help with translating an object model to a relational mode
Hi Jon, Jon wrote:> I need some help translating the > object model to a relational one:<snip>> 1. What is the proper way to do this? > =>How do I store an array in the database? > =>How do I tell activerecord to create a column for an array?This may not be what you''re looking for but my understanding (admittedly very weak ;-) ) of your problem leads me to initially suggest you treat this as a has-many relationship with a record in a seperate table for each element in your array. If that doesn''t make any sense in your case, perhaps you could say more about your problem, especially the object model you''re working with. Best regards, Bill
Maybe Matching Threads
- I only want one type of model returned from a multi_search
- Errno::EBADF Send an Email in Rails using GMail
- Problem with joins and overlapping field names
- add_multiple_associated_save_callbacks and validates_associated conflict?
- Having a problem adding a foreign key