XF 2.3 Database architecture question (relations?)

Anatoliy

Well-known member
So I built an add-on (slightly modified Notes add-on from Building with XF 2 videos).

PHP:
<?php

namespace AV\Notes\Entity;

use XF\Mvc\Entity\Entity;
use XF\MVC\Entity\Structure;

class Note extends Entity
{

    public static function getStructure(Structure $structure): Structure
    {
        $structure->table = 'av_notes_note';
        $structure->shortName = 'AV\Notes:Note';
        $structure->contentType = 'av_notes_note';
        $structure->primaryKey = 'note_id';
        $structure->columns = [
            'note_id' => ['type' => self::UINT, 'autoIncrement' => true],
            'user_id' => ['type' => self::UINT, 'default' => \XF::visitor()->user_id],
            'post_date' => ['type' => self::UINT, 'default' => \XF::$time],
            'from' => ['type' => self::STR, 'default' => '00:00'],
            'till' => ['type' => self::STR, 'default' => '23:59'],
            'quality' => ['type' => self::STR],
            'content' => ['type' => self::STR],
            'steelhead' => ['type' => self::UINT, 'default' => 0],
            'salmon' => ['type' => self::UINT, 'default' => 0],
            'trout' => ['type' => self::UINT, 'default' => 0],
            'bass' => ['type' => self::UINT, 'default' => 0],
            'tuna' => ['type' => self::UINT, 'default' => 0],
            'lingcod' => ['type' => self::UINT, 'default' => 0],
            'panfish' => ['type' => self::UINT, 'default' => 0],
        ];
        $structure->relations = [
            'User' => [
                'entity' => 'XF:User',
                'type' => self::TO_ONE,
                'conditions' => 'user_id',
                'primary' => true,
            ],
        ];
        $structure->defaultWith = ['User'];
        $structure->getters = [];
        $structure->behaviors = [];

        return $structure;
    }
}

Now I want to add an option to add a water body, that was fished (by selecting from a drop-down). And It's on a border of my knowledge and I barely understand how to do that.

Do I need to add two more tables?
One for the list of water bodies, and another table where add-on will add Note id and Water body id?

Please untangle me. )
 
Just had a cup of coffee and realized that I don't need two extra tables for that. Just one additional table 'water_bodies' and an additional column 'water_body' in my main 'av_notes_note' table. :unsure:
Right?
 
Hello,

For a select one column.

Then it all depends on what you want to do. Whether the list of water bodies will be dynamic via a defined table or list.
 
Hello,

For a select one column.

Then it all depends on what you want to do. Whether the list of water bodies will be dynamic via a defined table or list.
Thanks!
Yeah, I guess I better put water bodies in a separate table - there are a loooot of them ).

I created a table water_body and filling it with data. I guess after that I will stuck with the 'relations' thingy. )
 
Thanks!
Yeah, I guess I better put water bodies in a separate table - there are a loooot of them ).

I created a table water_body and filling it with data. I guess after that I will stuck with the 'relations' thingy. )
You will need to create a relationship with a unique ID in the water_body table.
 
Back
Top Bottom