I have a m-n
relationship between two tables using a pivot table. In the migration of the pivot table, I created it with a deleted_at
field, using the softDeletes()
method, like this:
public function up()
{
Schema::create('customer_store', function (Blueprint $table) {
$table->increments('id');
/** Satisfacción */
$table->char('satisfaccion', 1)->nullable();
/** Los campos de fechas */
$table->timestamps();
$table->softDeletes();
/** La definición de los campos que se usarán como claves foráneas */
$table->integer('customer_id')->unsigned();
$table->integer('store_id')->unsigned();
/** La declaración de las claves foráneas en los campos necesarios. */
$table->foreign('customer_id')->references('id')->on('customers');
$table->foreign('store_id')->references('id')->on('stores');
});
}
Also, as you can see, I've also added a field called satisfaccion
. The goal is for the same relationship to include data that is inherent in that relationship.
The point is that when the elements are disassociated (customers and stores), I do not want the relationship to be deleted, as it must remain historical, due to traceability issues. However, the detach()
method does not look for a deleted_at
field. Eliminate the relationship for good.
Is there a specific method for relationships to be marked in the deleted_at
field, or would I have to manually program it using the pivot table model?
And then the most important thing. When it comes to obtaining a list of customers related to a store, how can I decide if I want to see all the relationships, or only those that are active (that have null
in deleted_at
)?