deiucanta / laravel-smart

Automatic Migrations, Validation and More
48 stars 7 forks source link

What if relations were defined as fields? #17

Open deiucanta opened 6 years ago

deiucanta commented 6 years ago
Field::make('comments')->hasMany(Comment::class);
robsontenorio commented 6 years ago

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 ...
}
deiucanta commented 6 years ago

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.

robsontenorio commented 6 years ago

If it can be optional , no problem.

Em qui, 30 de ago de 2018 às 04:42, Andrei Canta notifications@github.com 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 commented 6 years ago

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 ...
}
deiucanta commented 6 years ago

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 commented 6 years ago

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).

robsontenorio commented 6 years ago

Ok, I will trust on you, haha

Em sáb, 1 de set de 2018 às 10:30, Andrei Canta notifications@github.com 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