# Save object reference in db?

**URL:** <https://www.ruby-forum.com/t/save-object-reference-in-db/151877>\
**Category:** Ruby\
**Created:** [October 27, 2008, 1:16pm UTC](https://www.ruby-forum.com/t/save-object-reference-in-db/151877 "2008-10-27T13:16:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [October 27, 2008, 1:16pm UTC](https://www.ruby-forum.com/t/save-object-reference-in-db/151877/1 "2008-10-27T13:16:09Z")

</div>

Hi everyone,

I want to ask if it’s possible to save object reference in database for  
later use?

Regards,  
Jamal

---

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [October 27, 2008, 2:14pm UTC](https://www.ruby-forum.com/t/save-object-reference-in-db/151877/2 "2008-10-27T14:14:55Z")

</div>

2008/10/27 Jamal S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I want to ask if it’s possible to save object reference in database for  
> later use?

No, not directly. How should that work?

You either need an OR mapper (for example ActiveRecord) or you store  
complete object graphs serialized (via Marshal in a BLOB or YAML in a  
CLOB).

Cheers

robert

---

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [October 27, 2008, 3:14pm UTC](https://www.ruby-forum.com/t/save-object-reference-in-db/151877/3 "2008-10-27T15:14:37Z")

</div>

Robert K. wrote:

> 2008/10/27 Jamal S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > I want to ask if it’s possible to save object reference in database for  
> > later use?
> 
> No, not directly. How should that work?

Well, technically it _is_ possible to save object references - see  
weakref.rb for an implementation.

But this is almost certainly not what the OP wants (since those object  
references won’t survive garbage collection, or application restart)

---

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [October 27, 2008, 4:51pm UTC](https://www.ruby-forum.com/t/save-object-reference-in-db/151877/4 "2008-10-27T16:51:31Z")

</div>

2008/10/27 Brian C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Robert K. wrote:
> 
> > 2008/10/27 Jamal S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> > 
> > > I want to ask if it’s possible to save object reference in database for  
> > > later use?
> > 
> > No, not directly. How should that work?
> 
> Well, technically it _is_ possible to save object references - see  
> weakref.rb for an implementation.

Hey, normally _I_ am supposed to be the nitpick! What’s the point in  
storing something that you cannot reasonably retrieve? This is only  
useful for a WOM. _gg_

> But this is almost certainly not what the OP wants (since those object  
> references won’t survive garbage collection, or application restart)

Exactly!

Kind regards

robert
