ivandoric / Making-Websites-With-October-CMS

This is a repository for video tutorial series about making websites with October CMS. You can check out the series here: https://goo.gl/eW32CM
160 stars 52 forks source link

Pivot table relations of categories #1

Closed tsiika closed 7 years ago

tsiika commented 7 years ago
Expected behavior

In part 10 of tutorial we are creating categories to our movies. In movie menu you should be able to create categories to movies and when you make new movie to list or modify existing movie entry you should be able to put the movie in the categories. Also you should be able to see categories in frontend side of selected movie.

Actual behavior

When you try to modify movie and try to give movie an category, the page gives error code:

"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'octotest_movies_movies_genres.add_stuff_id' in 'where clause' (SQL: selectoctotestmovies.idfromoctotestmoviesinner joinoctotest_movies_movies_genresonoctotestmovies.id=octotest_movies_movies_genres.add_movies_idwhereoctotest_movies_movies_genres.add_movies_id= 1 order bygenres_titleasc)" on line 662 of /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php"

octotest_movies_movies_genres structure is like it should be according to tutorial:

movie_id Integer Primary-Key genre_id Integer Primary-Key

I tried to modify the models and the database tables if that would get this problem fixed but I couldn't get it to work..

Reproduce steps

Followed steps of tutorial.

  1. Created octotest_movies_genres database table
  2. Created model for Genre
  3. Created forms and lists to Genre

Field.yaml

fields:

genre_title:

    label: Title

    oc.commentPosition: ''

    span: left

    type: text

slug:

    label: Slug

    span: right

    oc.commentPosition: '

    preset:

        field: genre_title

        type: slug

    type: text

columns.yaml

columns:

genre_title:

    label: Title

    type: text

`

  1. Made sub-item for Movies menu-item
  2. Created controller for genres
  3. Created few example genres to categories. These examples worked properly.
  4. Created octotest_movies_movies_genres
  5. Modifies Movies model fields.yaml and added genres relation
  6. Modified /Movies/Models/Movie.php and added following code:

public $belongsToMany =[ 'genres' =>[ 'octotest\Movies\Models\AddStuff', 'table' => 'octotest_movies_movies_genres', 'order' => 'genres_title', ] ];

After this the problem occured.

October build

(October build 382)

ivandoric commented 7 years ago

What worries me is this line in SQL error message. octotest_movies_movies_genres.add_stuff_id , could you search your files for add_stuff because October must be getting that from somewhere. Can you check that please.

ivandoric commented 7 years ago

Ok, wait, now I see that you are calling AddStuff model in your relation. What's up with that? Your model should be called either movies, our you have to change movie_id to addstuff_id in your pivot table.

tsiika commented 7 years ago

I tried to look up for that add_stuff from my databases an from other files but it couldn't find anything related to that name. I decided to rebuild the whole plugin with same names as in and now I got it to work.

I think the main reason why this did not work is I named model and other parts with my own names and I might have the names mixed up in some point and that caused this not to work like it should. I have to be more careful and precise with the names in the future.

ivandoric commented 7 years ago

Yeah, this was definitely a naming problem.