# Accessing properties/fields that are multiple properties/fields "deep"

**URL:** <https://discourse.julialang.org/t/accessing-properties-fields-that-are-multiple-properties-fields-deep/118731>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 28, 2024, 7:19pm UTC](https://discourse.julialang.org/t/accessing-properties-fields-that-are-multiple-properties-fields-deep/118731 "2024-08-28T19:19:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgalenb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mgalenb/32/5645_2.png) [@mgalenb](https://discourse.julialang.org/u/mgalenb)\
**Post date:** [August 28, 2024, 7:19pm UTC](https://discourse.julialang.org/t/accessing-properties-fields-that-are-multiple-properties-fields-deep/118731/1 "2024-08-28T19:19:01Z")

</div>

Not sure exactly the best way to phrase the question. I have a bunch of custom types that get stacked together and I am trying use `getproperty` to get at things buried in these types.

```julia
struct Foo
a::Integer
b::Integer
end

```

```julia
struct Bar
c::Foo
end

```

Then

```julia
foo=Foo(1,2)
bar=Bar(foo)

```

I can access the `a` field of `bar` by doing

```julia
bar.c.a
1

```

But I get an error if I do

```julia
getproperty(bar,Symbol("c.a"))
ERROR: type Bar has no field c.a

```

What am I doing incorrectly?

---

<div class="post-metadata">

**Author:** ![JonasWickman](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@JonasWickman](https://discourse.julialang.org/u/JonasWickman)\
**Post date:** [August 28, 2024, 7:29pm UTC](https://discourse.julialang.org/t/accessing-properties-fields-that-are-multiple-properties-fields-deep/118731/2 "2024-08-28T19:29:42Z")

</div>

I’m not entirely sure if this will help, but `bar.c.a` is essentially the same call as

```julia
getproperty(getproperty(bar, :c), :a)

```

i.e., recursive `getproperty` calls.

---

<div class="post-metadata">

**Author:** ![mgalenb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mgalenb/32/5645_2.png) [@mgalenb](https://discourse.julialang.org/u/mgalenb)\
**Post date:** [August 28, 2024, 7:38pm UTC](https://discourse.julialang.org/t/accessing-properties-fields-that-are-multiple-properties-fields-deep/118731/3 "2024-08-28T19:38:22Z")

</div>

I realize I need a bit more context to explain what I want to do

the reason I dont want to do that is that I have things buried multiple layers ie `a.b.c.d` and I want to have a “clean up” function that goes to certain fields and sets them to `nothing` for managing memory and multithreading purposes. so something like this

```julia
a = MyDeepStruct
keep = [Symbol("b.c.d"),Symbol("e.f.g")]
function clean(a,keep)
     for s in keep
          setproperty!(a,s,nothing)
     end
end

```

something like that…

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [August 28, 2024, 7:39pm UTC](https://discourse.julialang.org/t/accessing-properties-fields-that-are-multiple-properties-fields-deep/118731/4 "2024-08-28T19:39:18Z")

</div>

Check the Accessors.jl package out.
