Model with no primary key

Hi,

I have looked around quite a bit, and haven’t found any workable
solution to this.

I am accessing an external/remote database from my rails app, in order
to update a categories table.

I cannot change the table structure of the remote database. it has a
categories table with an id field but has a one to one relationship
with a descriptions table.

The descriptions table has no primary key, only a categories_id.

Setting up a one-to-one relationship in my model allows me to load the
description along with the category. But I need to be able to create
a new category and description and cannot find a way around creating
an ActiveRecord object without a primary key.

Grateful for any suggestion of how to do this. I am wondering if I
can use sql from within the model, but not quite sure how this would
be done.

Tony

On Mar 17, 9:37am, tonypm [email protected] wrote:

with a descriptions table.
be done.

Could you just tell rails that categories_id is the primary key? If
it’s unique then that should be good enough (you’ll probably have to
be a little careful when creating rows in this table though, as you’ll
need to set categories_id each time)

Fred

What is your rails version?

On Mar 17, 11:04am, Frederick C. [email protected]
wrote:

Could you just tell rails that categories_id is the primary key? If
it’s unique then that should be good enough (you’ll probably have to
be a little careful when creating rows in this table though, as you’ll
need to set categories_id each time)

You are quite right Fred. I think I must have confused myself. I
initially tried to bulk assign using create, but this resulted in the
categories id not getting set. I thought i had tried using new and
setting the categories_id before saving, but I must have confused
myself. I have just tried it again and it works.

Many Thanks

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs