C
C
chelkaz2017-03-08 13:31:25
Laravel
chelkaz, 2017-03-08 13:31:25

How to properly add to linked table?

Maybe my logic is not correct at all? Then I'll be glad to hear your opinion.
I have about 500,000 titles. And up to a million records can be added to any of them.
The entry has a name, type, and the text itself and the id of the name.
To store this in one table, I think is not right, so I created 2 tables, for the text and another for the id links.
----------------------
In one field text_id and loc_id
In another text_id title text type
and in the main table where all names name and loc_id
Tables are all connected.
It turns out if I add an entry for the name with id 15,

$post = new Post;
        $post->loc_id = $id;
        $post->text_id = // Но я же его еще не знаю, поэтому сперва нужно добавить текста?
        $post->save();

Then first it turns out to do so?
// Тут добавить сам текст в таблицу для текста и после добавления получить id
        // А потом уже это?
        $post = new Post;
        $post->loc_id = $id;
        $post->text_id = // и тут полученный id
        $post->save();

But I'm wondering if that's not possible?
$post = new Post(['loc_id' => $id])
$post->text()->save([
    new App\text(['title' => 'A new title']);

What would one record add like this, and the system automatically put down the id for the links.
Maybe you need polymorphs?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
holfza, 2017-03-08
@holfza

You can: https://laravel.com/docs/5.4/eloquent-relationship...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question