# Supporting/emulating updatable views in a ruby orm

**URL:** <https://www.ruby-forum.com/t/supporting-emulating-updatable-views-in-a-ruby-orm/48918>\
**Category:** Ruby\
**Created:** [November 26, 2005, 9:28pm UTC](https://www.ruby-forum.com/t/supporting-emulating-updatable-views-in-a-ruby-orm/48918 "2005-11-26T21:28:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [November 26, 2005, 9:28pm UTC](https://www.ruby-forum.com/t/supporting-emulating-updatable-views-in-a-ruby-orm/48918/1 "2005-11-26T21:28:46Z")

</div>

i’ve got a method to emulate updateable views in postgresql which is  
rather  
simple. however, i’m wondering if any of the ruby orms out there would  
support such a beast. for example, given:

```
 create table foo(
   foo text,
   id serial,

   primary key (id)
 );

 create table bar(
   bar text,
   foo_id integer,
   id serial,

   primary key (id),
   foreign key (foo_id) references foo (id)
 );

 create view foobar as
   select
     foo.foo as foo,
     bar.bar as bar
   from foo, bar
   where foo.id = bar.foo_id;

```

i need to be able to do something like this:

db = DB::new options

foo = db.table “foo”  
bar = db.table “bar”

foobar = db.view “foobar”

foobar[0][“foo”] = “42”  
foobar[0][“bar”] = “forty-two”

p foo[0][“foo”] #=\> “42”  
p bar[0][“bar”] #=\> “forty-two”

i can do this using my code if the view is constructed a certain way,  
but i’m  
wondering of any of the existing orms have addressed this rather common  
need?

regards.

-a

---

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [November 28, 2005, 9:52am UTC](https://www.ruby-forum.com/t/supporting-emulating-updatable-views-in-a-ruby-orm/48918/2 "2005-11-28T09:52:58Z")

</div>

Ara.T.Howard schrieb:

> ```
> );
> create view foobar as
> 
> ```
> 
> foo = db.table “foo”  
> i can do this using my code if the view is constructed a certain way,  
> but i’m  
> wondering of any of the existing orms have addressed this rather common  
> need?

Ara, I don’t have an answer for you, but some more questions. If I  
understand your code, you want to create new rows via the view foobar.

Do you want to create a new foo for every new bar? I don’t think so,  
otherwise you could have both in the same table.

Do you want to allow two foos to have the same text? If not, you should  
add a unique key on the foo column to the foo table. Only then it should  
be possible to do what you want.

But as I said, I can’t tell you anything about the Ruby ORM frameworks.

Regards,  
Pit
