A
A
akdes2017-06-13 16:42:08
Laravel
akdes, 2017-06-13 16:42:08

Egg or Chicken in Laravel-Eloquent?

Hi all.
I spend the whole day planning a new project and creating database and model migrations in laravel.
The logic of tables and the verbal meaning of links in laravel does not converge in my head (maybe just tired?)
There is a good standard example: Post::Comments
Post

id
text

Comment
id
text
post_id

Post hasMany Comments <-> Comment belongsTo Post
Here, in principle, everything is clear and logical.
But here I have a real example:
Table Product
id
name
period_id

Table Period (time period)
id
name

Time table
id
from
to

My problem is in the logic of connection between Period & Time:
Period consists of time. According to my logic, I refer from the Period to the time, i.e. in the time_id period table,
but verbally the language does not turn to say Period belongsTo Time <-> Time hasOne Period
Technically, I can use both options, but I want to understand and understand.
When answering, please explain the logic of your choice. Thanks a lot.
UPDATE:
Another example:
Position
id
name

point
id
x
y

Logically, in order to describe the position of a rectangular figure, two links are needed in the position: start_point_id & end_point_id both refer to Point
but verbally again garbage:
Position belongsTo Point <-> Point hasOne Position

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Aksentiev, 2017-06-13
@Sanasol

Time from - to = this is the period.
What for still the table with any name?
Why not in one table for example.
Why not automatically count from - to and output "name".
The problem could have been better explained. You ask about logic, but do not explain what logic should do.

I
imhuman, 2017-06-13
@imhuman

Well, apparently you get a one-to-one connection, you should think, why is it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question