# Deep v. Shallow Copies

**URL:** <https://forum.bubble.io/t/deep-v-shallow-copies/120234>\
**Category:** Database\
**Created:** [November 9, 2020, 6:03pm UTC](https://forum.bubble.io/t/deep-v-shallow-copies/120234 "2020-11-09T18:03:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkesselman2019](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@jkesselman2019](https://forum.bubble.io/u/jkesselman2019)\
**Post date:** [November 9, 2020, 6:03pm UTC](https://forum.bubble.io/t/deep-v-shallow-copies/120234/1 "2020-11-09T18:03:04Z")

</div>

When you copy a thing, are references in that thing to other things copied as references or are copies made of the things referenced?

When copying a list of things, are just the references in the list copied, or do you get back a list of new things copied from the thinsg in the original list?

Thanks

---

<div class="post-metadata">

**Author:** ![jkesselman2019](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@jkesselman2019](https://forum.bubble.io/u/jkesselman2019)\
**Post date:** [November 9, 2020, 6:59pm UTC](https://forum.bubble.io/t/deep-v-shallow-copies/120234/2 "2020-11-09T18:59:58Z")

</div>

Allright, based on experiments, th answer is both ☹  
When you copy a list of objects, the objects in the list get duplicated, but their fields get shallow copied.

SO I’m now beating my head against how to deep copy a list of lists…

Edit: I could do it with a recursive back-end workflow. I wish there was a simpler way though…

---

<div class="post-metadata">

**Author:** ![NigelG](https://avatars.discourse-cdn.com/v4/letter/n/ea5d25/32.png) [@NigelG](https://forum.bubble.io/u/NigelG)\
**Post date:** [November 9, 2020, 7:22pm UTC](https://forum.bubble.io/t/deep-v-shallow-copies/120234/3 "2020-11-09T19:22:00Z")

</div>

I think a bit more explanation on “deep copy” would help as we may well be thinking about different things.

---

<div class="post-metadata">

**Author:** ![cmarchan](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/cmarchan/32/253062_2.png) [@cmarchan](https://forum.bubble.io/u/cmarchan)\
**Post date:** [November 9, 2020, 9:52pm UTC](https://forum.bubble.io/t/deep-v-shallow-copies/120234/4 "2020-11-09T21:52:58Z")

</div>

Agree with @NigelG. What is meant by deep copy?

---

<div class="post-metadata">

**Author:** ![jkesselman2019](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@jkesselman2019](https://forum.bubble.io/u/jkesselman2019)\
**Post date:** [November 9, 2020, 10:24pm UTC](https://forum.bubble.io/t/deep-v-shallow-copies/120234/5 "2020-11-09T22:24:51Z")

</div>

Deep and Shallow copy are computer science terms.

A deep copy of a variable copes the value of the variable so you have 2 separate variables.  
A shallow copy just copies a refence to a variable (often, but nto always, a memory address) so you have a single variable referred to in multiple ways.

In databases, the idea extends by analogy. A deep copy is a new record. A shallow copy is another field referring to the same primary key.

---

<div class="post-metadata">

**Author:** ![NigelG](https://avatars.discourse-cdn.com/v4/letter/n/ea5d25/32.png) [@NigelG](https://forum.bubble.io/u/NigelG)\
**Post date:** [November 10, 2020, 2:01pm UTC](https://forum.bubble.io/t/deep-v-shallow-copies/120234/6 "2020-11-10T14:01:53Z")

</div>

I don’t think Bubble will like it, as there is the potential for it to run forever.

You can copy a list of things…

> **[Bubble Reference](https://bubble.io/reference#Actions.CopyListOfThings)**
>
> Full reference for each Bubble element, feature, plugin. Bubble is a visual programing language. Instead of typing code, use a visual editor to build applications.

---

<div class="post-metadata">

**Author:** ![deadpoetnsp](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/deadpoetnsp/32/64992_2.png) [@deadpoetnsp](https://forum.bubble.io/u/deadpoetnsp)\
**Post date:** [November 10, 2020, 6:29pm UTC](https://forum.bubble.io/t/deep-v-shallow-copies/120234/7 "2020-11-10T18:29:36Z")

</div>

You can try using backend workflows to recursively _create_ Things and then copy the contents. For example, let’s say a User has a list of Posts. Instead of copying User, create a new User, create a list of new Posts, and copy the contents of the posts.

---

<div class="post-metadata">

**Author:** ![cmarchan](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/cmarchan/32/253062_2.png) [@cmarchan](https://forum.bubble.io/u/cmarchan)\
**Post date:** [November 10, 2020, 7:13pm UTC](https://forum.bubble.io/t/deep-v-shallow-copies/120234/8 "2020-11-10T19:13:08Z")

</div>

@jkesselman2019

It seems nested recursive backend workflows is the way to go. Custom-built as opposed to any vanilla action specific for this use case.

---

<div class="post-metadata">

**Author:** ![jkesselman2019](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@jkesselman2019](https://forum.bubble.io/u/jkesselman2019)\
**Post date:** [November 11, 2020, 2:20am UTC](https://forum.bubble.io/t/deep-v-shallow-copies/120234/9 "2020-11-11T02:20:24Z")

</div>

Yeah that seems to be the answer for bubble.

Avoiding infinite loops on a directed potentially cyclic graph is a relatively easy computer science problem, btw. You just use a node index for already visited nodes. Basic hashtable works great for this.
