Hi,
I have just come across an article which states that primary keys must be auto-increment and id(which I know can be overridden). So when I am dealing, in hibernate, with the following:
which basically says that the primary id is ‘assigned’ and mapped to the artist_id column of the artisttbl with a one to many relationship against the artistimagestbl, the artist_id being the Foreign key, how would this be reflect in ActiveRecord? The database schema alraeady exists, I just want to see how ruby/rails/activerecord would reflect this in actual code.
What actual rails/activerecord command would be needed to say 'go away to this dB and create all the required activrecord classes based on the dB schema?
Assignable meaning not auto_increment and you take care of the value yourself? ActiveRecord doesn’t really like that. It basically requires that it take care of handling the primary key. I’m not sure if there’s a plugin to work around this, but you’ll probably have to jump into AR itself if you start getting crazy with the keys.
Unless of course someone knows a proper way of doing this.
Assignable meaning not auto_increment and you take care of the value yourself?
Yes.
ActiveRecord doesn’t really like that. It basically requires that it take care of handling the primary key.
Hmmm…not so good! Let’s say you have an order object with corresponding order items FKey referenced by order_id. If the order table is auto generating its own id and each order item is also doing the same…nothing will work, plus I can’t change the table structure as it is needed by another system!!!
I’m not sure if there’s a plugin to work around this, but you’ll probably have to jump into AR itself if you start getting crazy with the keys.
This is a very standard, basic model setup. It will work just fine in
Rails. Generate models for order and order item, then add to order.rb:
has_many :order_items
add to order_item.rb
belongs_to :order
and Rails will work as you describe. The curious thing is why you
don't trust Hibernate to perform id management for you? Are you doing
something unusual?