Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InitialSchemaSeeder issue #280

Closed
sanalkr opened this issue Sep 1, 2019 · 0 comments

Comments

@sanalkr
Copy link

commented Sep 1, 2019

Error while adding currencies:
The below seeder code fails as there is no iso_alpha2 in countries table.

    protected function seedCurrencies()
    {
        if (Currencies_model::count())
            return;

        $currencies = $this->getSeedRecords('currencies');

        foreach ($currencies as $currency) {
            $country = Countries_model::where('iso_alpha2', $currency['iso_alpha2'])->first();
            $currency['country_id'] = $country->country_id;
            Currencies_model::insert($currency);
        }
    }

Also it fails sometime at this statement
$currency['country_id'] = $country->country_id;
with error as " Trying to get property 'country_id' of non-object"

Version:
Ver 3 Beta

Fixed it with following update:
Though I am not a PHP expert, I updated it as below to make it work

    protected function seedCurrencies()
    {
        if (Currencies_model::count())
            return;

        $currencies = $this->getSeedRecords('currencies');

        foreach ($currencies as $currency) {
            $country = Countries_model::where('iso_code_2', $currency['iso_alpha2'])->first();
			if(isset($country))
				$currency['country_id'] = $country->country_id;
			else {
                $currency['country_id'] = 1;
            }

            Currencies_model::insert($currency);
        }
    }

(Additional information, if any)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.