# UserField custom\_field reference

**URL:** https://meta.discourse.org/t/userfield-custom-field-reference/120883
**Category:** Development
**Created:** [June 20, 2019, 8:40am UTC](https://meta.discourse.org/t/userfield-custom-field-reference/120883 "2019-06-20T08:40:33Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![csmu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/csmu/32/124581_2.png) [@csmu](https://meta.discourse.org/u/csmu)
#### Post date: [June 20, 2019, 8:40am UTC](https://meta.discourse.org/t/userfield-custom-field-reference/120883/1 "2019-06-20T08:40:33Z")

</div>

I have determined that user\_field\_15 implicitly maps to UserField(id:15)  
and user\_field\_1 implicitly maps to UserField(id:1)

Is there any explicit mapping for UserField or is it explicitly user\_field\_n where n is the id for the UserField record?

Context

```plaintext
[79] pry(main)> user.custom_fields
=> {"user_field_2"=>"xxxx",
 "user_field_1"=>"xxxx-xxx-xxx",
 "user_field_4"=>"Fulltime",
 "user_field_8"=>"true",
 "user_field_9"=>"false",
 "user_field_13"=>"true",
 "user_field_15"=>"true"}

user_field = UserField.find_by_name("Mobile")
=> #<UserField:0x00005635bff79158
 id: 1,
 name: "Mobile",
 field_type: "text",
 created_at: Fri, 01 Feb 2019 23:05:43 UTC +00:00,
 updated_at: Mon, 08 Apr 2019 04:50:11 UTC +00:00,
 editable: true,
 description: "Your Mobile Number",
 required: false,
 show_on_profile: false,
 position: 1,
 show_on_user_card: false,
 external_name: nil,
 external_type: nil>
[81] pry(main)> 

```

---

<div class="post-metadata">

### Author: ![weallwegot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/weallwegot/32/124753_2.png) [@weallwegot](https://meta.discourse.org/u/weallwegot)
#### Post date: [September 4, 2020, 10:58pm UTC](https://meta.discourse.org/t/userfield-custom-field-reference/120883/2 "2020-09-04T22:58:57Z")

</div>

Sorry for Bumping this, i realize that the `user_fields` and `user_custom_fields` tables use the `id` & `name` columns respectively as a sort of “soft relationship”, but was just curious from a design perspective why it’s not a direct foreign key linking? I’m sure theres a good reason, but would love to learn specifically what went into the database design decision!

thanks
