Body: <p>i have created my first plugin and have hit a bit of a wall... its a plugin with a custom element type, i have it creating its own database table (migrations/install.php) and i have the form displaying, and the bit i am struggling with is the saving bit. I build a new element type based on the form details, then do a Craft::$app-&gt;getElements()-&gt;saveElement($song); ($song is my element type) , i keep getting a getSection method missing error from my Song element type, but i dont have a sectionId, or need a section for this as it is stored entirely in its own table, what have i not understood about creating and saving a custom element type?</p>
  <p>Is there a demo plugin or some example i can learn from?</p>
  <p>This is my controller</p>
  <pre><code>new SongElementType();
  $SongElementType-&gt;name = Craft::$app-&gt;request-&gt;getParam('name', $SongElementType-&gt;name);
  $SongElementType-&gt;band = Craft::$app-&gt;request-&gt;getParam('band', $SongElementType-&gt;band);
  </code></pre>
  <p>then i call save that is in my service from my controller like so:</p>
  <pre><code>songscatalogue::getInstance()-&gt;SongsService-&gt;saveSong($SongElementType)
  </code></pre>
  <pre><code>            $this-&gt;trigger(self::EVENT_SONG_SAVED_BEFORE, new SongEvent([
                  'song' =&gt; $song,
                  'isNew' =&gt; $isNew,
              ]));
  
              $success = Craft::$app-&gt;getElements()-&gt;saveElement($song);
  
              $this-&gt;trigger(self::EVENT_SONG_SAVED_AFTER, new SongEvent([
                  'song' =&gt; $song,
                  'isNew' =&gt; $isNew,
              ]));
  </code></pre>
  <p>but i get this error:</p>
  <pre><code>Calling unknown method: robsplugin\songscatalogue\elements\Song::getSection()
  
  </code></pre>
  <p>where am i going wrong?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-10-18T23:23:20.793Z
Comments.Text: Is the method getSection() inside your Song class static and accessible from where you are calling it?
Comments.UserDisplayName: Tim Strawbridge
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-10-19T09:16:34.287Z
Comments.Text: I created my element type with a complete set of empty methods for reference, not realising that their presence alone would trigger a different outcome. Once i deleted them all to ones i actually use, it has started working.
Comments.UserDisplayName: bpmedia
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-10-19T11:38:11.560Z
Comments.Text: Just out of curiosity, what made you go for a completely new element type, including your own tables and events, instead of a using normal entries for it? I've been considering something similar for movies with corresponding shows, but I've so far not really found any big advantages to custom element types.
Comments.UserDisplayName: KSP
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-10-19T21:37:21.773Z
Comments.Text: It was purely an exercise to learn more about building plugins. I am finding the documentation to be lacking, with a lot of the docs pointing us to YII's docs, but they dont directly translate into craft.
Comments.UserDisplayName: bpmedia
Tags: <plugin-development><elementtype>
Title: Saving custom element types
ThreadText: # Saving custom element types
  
  (Asked by: username_0 on 2020-10-18)
  
  i have created my first plugin and have hit a bit of a wall... its a plugin with a custom element type, i have it creating its own database table (migrations/install.php) and i have the form displaying, and the bit i am struggling with is the saving bit. I build a new element type based on the form details, then do a Craft::$app->getElements()->saveElement($song); ($song is my element type) , i keep getting a getSection method missing error from my Song element type, but i dont have a sectionId, or need a section for this as it is stored entirely in its own table, what have i not understood about creating and saving a custom element type?
  
  Is there a demo plugin or some example i can learn from?
  
  This is my controller
  
  ```
  new SongElementType();
  $SongElementType->name = Craft::$app->request->getParam('name', $SongElementType->name);
  $SongElementType->band = Craft::$app->request->getParam('band', $SongElementType->band);
  
  ```
  
  then i call save that is in my service from my controller like so:
  
  ```
  songscatalogue::getInstance()->SongsService->saveSong($SongElementType)
  
  ```
  
  ```
              $this->trigger(self::EVENT_SONG_SAVED_BEFORE, new SongEvent([
                  'song' => $song,
                  'isNew' => $isNew,
              ]));
  
              $success = Craft::$app->getElements()->saveElement($song);
  
              $this->trigger(self::EVENT_SONG_SAVED_AFTER, new SongEvent([
                  'song' => $song,
                  'isNew' => $isNew,
              ]));
  
  ```
  
  but i get this error:
  
  ```
  Calling unknown method: robsplugin\songscatalogue\elements\Song::getSection()
  
  ```
  
  where am i going wrong?
  
  **Tags:** plugin-development, elementtype
  
  > **Comments:**
  > **username_1**: Is the method getSection() inside your Song class static and accessible from where you are calling it?  
  > **username_0**: I created my element type with a complete set of empty methods for reference, not realising that their presence alone would trigger a different outcome. Once i deleted them all to ones i actually use, it has started working.  
  > **username_2**: Just out of curiosity, what made you go for a completely new element type, including your own tables and events, instead of a using normal entries for it? I've been considering something similar for movies with corresponding shows, but I've so far not really found any big advantages to custom element types.  
  > **username_0**: It was purely an exercise to learn more about building plugins. I am finding the documentation to be lacking, with a lot of the docs pointing us to YII's docs, but they dont directly translate into craft.  
  
  ---
  
  ## 0 answers
  
  