UserField custom_field reference

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

[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)> 

1 Like

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

1 Like