{"action":"opened","issue":{"url":"https://api.github.com/repos/serverfireteam/panel/issues/305","repository_url":"https://api.github.com/repos/serverfireteam/panel","labels_url":"https://api.github.com/repos/serverfireteam/panel/issues/305/labels{/name}","comments_url":"https://api.github.com/repos/serverfireteam/panel/issues/305/comments","events_url":"https://api.github.com/repos/serverfireteam/panel/issues/305/events","html_url":"https://github.com/serverfireteam/panel/issues/305","id":194412350,"number":305,"title":"Editing crud One to One relationship, when relation record doesn't exist yet","user":{"login":"xdvx","id":5551933,"avatar_url":"https://avatars.githubusercontent.com/u/5551933?v=3","gravatar_id":"","url":"https://api.github.com/users/xdvx","html_url":"https://github.com/xdvx","followers_url":"https://api.github.com/users/xdvx/followers","following_url":"https://api.github.com/users/xdvx/following{/other_user}","gists_url":"https://api.github.com/users/xdvx/gists{/gist_id}","starred_url":"https://api.github.com/users/xdvx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xdvx/subscriptions","organizations_url":"https://api.github.com/users/xdvx/orgs","repos_url":"https://api.github.com/users/xdvx/repos","events_url":"https://api.github.com/users/xdvx/events{/privacy}","received_events_url":"https://api.github.com/users/xdvx/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-08T18:43:03Z","updated_at":"2016-12-08T18:43:03Z","closed_at":null,"body":"This is in my Controler:\r\n\r\nLoading module\r\n`$this->relationModel = Account::with('categories', 'amazon');`\r\n\r\nSetting editable grid for relation fields:\r\n\r\n```\r\n$this->edit->add('amazon.sku_prefix', 'SKU Prefix', 'text')->rule('required');\r\n$this->edit->add('amazon.mws_auth_token', 'MWS Auth Token', 'text');\r\n$this->edit->add('amazon.merchant_id', 'Merchant ID', 'text');\r\n```\r\n\r\n\r\nMy account table model:\r\n\r\n```\r\nclass Account extends Model\r\n{\r\n    /**\r\n     * @var string\r\n     */\r\n    protected $table = 'accounts';\r\n\r\n    /**\r\n     * @var bool\r\n     */\r\n    public $timestamps = true;\r\n\r\n    /**\r\n     * @var array\r\n     */\r\n    protected $fillable = ['username', 'products', 'max_products'];\r\n\r\n    /**\r\n     * @return \\Illuminate\\Database\\Eloquent\\Relations\\BelongsToMany\r\n     */\r\n    public function categories()\r\n    {\r\n        return $this->belongsToMany(Category::class, 'account_categories');\r\n    }\r\n\r\n    /**\r\n     * @return \\Illuminate\\Database\\Eloquent\\Relations\\BelongsToMany\r\n     */\r\n    public function files()\r\n    {\r\n        return $this->hasMany(Category::class, 'account_categories');\r\n    }\r\n    \r\n    /**\r\n     * @return \\Illuminate\\Database\\Eloquent\\Relations\\HasOne\r\n     */\r\n    public function amazon()\r\n    {\r\n        return $this->hasOne(AccountAmazon::class, 'account_id');\r\n    }\r\n}\r\n```\r\n\r\nMy AccountAmazon model:\r\n```\r\nclass AccountAmazon extends Model\r\n{\r\n    /**\r\n     * @var string\r\n     */\r\n    protected $table = 'account_amazon';\r\n    \r\n    protected $primaryKey = 'account_id';\r\n    \r\n    protected $fillable = ['account_id', 'sku_prefix', 'merchant_id', 'mws_auth_token'];\r\n\r\n    /**\r\n     * @var bool\r\n     */\r\n    public $timestamps = false;\r\n    \r\n    /**\r\n     * @var bool\r\n     */\r\n    public $guarded = [];\r\n}\r\n```\r\n\r\n![accounts table](https://cloud.githubusercontent.com/assets/5551933/21022782/83f8b09c-bd86-11e6-99b5-f737645c2cfe.png)\r\n\r\n![account_amazon](https://cloud.githubusercontent.com/assets/5551933/21022788/877013d2-bd86-11e6-9b7c-e8f98a2721dc.png)\r\n\r\n\r\n\r\nQueries Laravel panel runs on save:\r\n![queries](https://cloud.githubusercontent.com/assets/5551933/21022412/3695e942-bd85-11e6-87ae-193e6722c455.png)\r\n\r\nFor first time, when relation record still doesn't exists it runs this nonsense query:\r\n`update `account_amazon` set `account_id` = '1', `mws_auth_token` = 'aaa' where `account_id` = '0';`\r\n\r\nIt only inserts 2 fields from 3. After record is created at database Update queries run just fine.\r\n"}}
{"actor":{"display_login":"xdvx"}}