Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent

I have a model that will contain information about a patient, the database migration for that table is below

Schema::create('patients', function(Blueprint $table)
		{
			$table->increments('id');
			$table->string('title')->nullable();
			$table->string('first_name');
			$table->string('last_name');
			$table->string('suffix')->nullable();
			$table->string('ssn', 9)->unique()->nullable();
			$table->date('dob');
			$table->integer('marital_status')->unsigned();
			$table->string('job_title')->nullable();
			$table->string('employer')->nullable();
			$table->integer('home_address')->unsigned()->nullable();
			$table->integer('work_address')->unsigned()->nullable();
			$table->integer('billing_address')->unsigned()->nullable();
			$table->integer('postal_address')->unsigned()->nullable();
			$table->integer('home_phone')->unsigned()->nullable();
			$table->integer('work_phone')->unsigned()->nullable();
			$table->integer('mobile_phone')->unsigned()->nullable();
			$table->integer('personal_email')->unsigned()->nullable();
			$table->integer('work_email')->unsigned()->nullable();
			$table->integer('preferred_address')->unsigned()->nullable();
			$table->integer('preferred_phone')->unsigned()->nullable();
			$table->integer('preferred_email')->unsigned()->nullable();
			$table->boolean('postal_mail_optin');
			$table->boolean('telephone_optin');
			$table->boolean('email_optin');
			$table->enum('primary_contact_method', array('postalMail, phone, email'));
			$table->integer('language')->unsigned();
			$table->text('notes');
			$table->timestamps();
			$table->softDeletes();
		});
  1. For any field like Primary Contact Method, where the values are a fixed list to the end user, but could change later, I'm used to making a simple lookup table and then referencing the ID number from the lookup table in the model. To replicate that with Eloquent, would I just use a one to many relationship with some new model I create for primary contact method? I feel like I'd end up with a lot of really thin models just to support these lookup tables in my application.

  2. For the addresses, phone numbers, and e-mails, I had planned to link those to appropriate tables for each type of information so I could reduce duplication of data in the patients table. Also, if a parent wanted to update contact information for the whole family, we could update one address record and then all patients linked to that address record will show the correct information when they're accessed.

To make that work though, do I have to write a separate relationship method for each address, phone, and email field?

As I'm starting to write this out in my app, I started feeling like I was going about this all wrong, so I paused to get some advice here :) I appreciate any input you can provide, including "that's an awful idea, here's why". While I'm familiar with database normalization, this seems a bit overkill, especially when you add the Eloquent relationship layer on top.

Thanks in advance!

-Nick

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.