laravel-smart icon indicating copy to clipboard operation
laravel-smart copied to clipboard

What if relations were defined as fields?

Open deiucanta opened this issue 6 years ago • 7 comments

Field::make('comments')->hasMany(Comment::class);

deiucanta avatar Aug 29 '18 08:08 deiucanta

I don't think a good idea, because sometimes you need customize relationships like this:

public funcion comments()
{
   return $this->hasMany(Comment::class)->orderBy('date'); // and so on ...
}

robsontenorio avatar Aug 29 '18 11:08 robsontenorio

For me it seems to be the same fluency as when defining fields. On fields you need to call multiple methods as well.

Field::make('projects')->hasMany(Project::class)->orderBy('created_at')->whereActive(true)

Currently we group field definitions which is good, but I feel the relations should be there as well since you access them similarly.

deiucanta avatar Aug 30 '18 07:08 deiucanta

If it can be optional , no problem.

Em qui, 30 de ago de 2018 às 04:42, Andrei Canta [email protected] escreveu:

For me it seems to be the same fluency as when defining fields. On fields you need to call multiple methods as well.

Field::make('projects')->hasMany(Project::class)->orderBy('created_at')->whereActive(true)

Currently we group field definitions which is good, but I feel the relations should be there as well since you access them similarly.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/deiucanta/laravel-smart/issues/17#issuecomment-417221857, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHQq7RgxZohtUJXmFKjoyielvcl8rs3ks5uV5dVgaJpZM4WRGSX .

-- — Robson Tenório

robsontenorio avatar Aug 30 '18 10:08 robsontenorio

I'm considering out of scope this package, once we will have a lot of concerns on field creation. Just my thoughts.

More things can happen in here..

public funcion comments()
{
   // some business thing in this line <---
   return $this->hasMany(Comment::class)->orderBy('date'); // and so on ...
}

robsontenorio avatar Sep 01 '18 02:09 robsontenorio

I'm not convinced yet :) Good things come from (initially) crazy ideas.

Let's consider this further. Also, please look at how Django models work.

deiucanta avatar Sep 01 '18 13:09 deiucanta

One advantage of having this would be that we can automate foreign keys based on the relations. Also, there is no way to create pivot tables with Laravel Smart (except by creating a separate model).

deiucanta avatar Sep 01 '18 13:09 deiucanta

Ok, I will trust on you, haha

Em sáb, 1 de set de 2018 às 10:30, Andrei Canta [email protected] escreveu:

One advantage of having this would be that we can automate foreign keys based on the relations. Also, there is no way to create pivot tables with Laravel Smart (except by creating a separate model).

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/deiucanta/laravel-smart/issues/17#issuecomment-417859898, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHQq4dzJbWeUOxwR0B_KIdSZ4KYxnMJks5uWov1gaJpZM4WRGSX .

-- — Robson Tenório

robsontenorio avatar Sep 01 '18 13:09 robsontenorio