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

Проблема с использованием поля relates #144

Open
zverbeta opened this issue May 7, 2016 · 3 comments
Open

Проблема с использованием поля relates #144

zverbeta opened this issue May 7, 2016 · 3 comments

Comments

@zverbeta
Copy link

zverbeta commented May 7, 2016

Всем привет. У меня не получается использовать поле relates
$schema->relates('order_id', 'orders')

Этот код возвращает ошибку

The target model [App\Product] doesn't have relation [order_id] defined.

Модели Order, Product

class Order extends Eloquent { public function products() { return $this->hasMany(Product::class); } }

class Product extends Eloquent { public function orders() { return $this->belongsTo(Order::class); } }

В чем может быть проблема?

@lazychaser
Copy link
Contributor

Нужно указывать имя отношения, а не атрибута, т.е. orders, а не order_id

@zverbeta
Copy link
Author

zverbeta commented May 7, 2016

т.е моя строчка в методе fields должны быть такой $schema->relates('orders', 'orders')

@zverbeta
Copy link
Author

zverbeta commented May 7, 2016

Я попробовал, по моему работает, только сейчас при сохранении проблемы. Такое ощущение что он сам пребразовует название поля таблицы. Указал orders как вы и советовали, но поле он ищет orders_id, а меня указано order_id. Как лучше всего поправить.

Спасибо за ответ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants