orchestral / tenanti

[Package] Multi-tenant Database Schema Manager for Laravel
MIT License
587 stars 53 forks source link

Using seeders in Single Database #56

Closed claytongf closed 7 years ago

claytongf commented 7 years ago

Hi, I'm trying to use seeders to set some data for users like below: public function run() { $user = User::find(1); Address::setTable("user_{$user->id}events"); Address::create([ 'address' => 'some address for user 1', 'number' => '123', 'city' => 'some city for user 1', ]); $user = User::find(2); Address::setTable("user{$user->id}_events"); Address::create([ 'address' => 'some address for user 2', 'number' => '321', 'city' => 'some city for user 2', ]); } But I get this error when running php artisan db:seed

[Illuminate\Database\QueryException] SQLSTATE[42S02]: Base table or view not found: 1146 Table 'app_tenant.addresses' doesn't exist (SQL: insert into addresses (address, number, city, updated_at, created_at) values (some address for user 1, 123 some city for user 1, 2017-10-06 18:45:06, 2017-10-06 18:45:06))

[PDOException] SQLSTATE[42S02]: Base table or view not found: 1146 Table 'app_tenant.addresses' doesn't exist

The correct table should be user_1_addresses, but it tries to find in addresses table which does not exist. How can I set up a specific table to create, find, delete, update data?

h2akim commented 7 years ago

I don't think tenanti support seeding yet. Not sure how you do the setTable method since setTable method cannot be called statically.

I think you can do like this

$user = User::find(1);
$address = new Address;
$address->setTable("user_{$user->id}_events");
$address->address = 'some address for user 1';
$address->number = '123';
$address->city = 'some city for user 1';
$address->save();
crynobone commented 7 years ago

We don't have plan to support seeder at the moment.