Answers.Body: <p>You can't set a property of an <code>element</code> in Craft that does not exists in the field layout, as a behavior or as a public/private attribute in the object. Craft/Yii2 will throw an exception because the property <code>instance_datetime</code> probably does not exist.</p>
  
  <p>In order to attach a custom value you have to either create a new <code>element</code> or you have to store this information somewhere else. </p>
  
  <h3>Edit</h3>
  
  <p>You could the following as well to fetch your values and store them into a new array</p>
  
  <pre><code>$query = Entry::find();
  $columns = $query
      -&gt;addSelect('craft_event_instances.instance_datetime')
      -&gt;innerJoin('craft_event_instances', 'craft_event_instances.entryId = elements.id')
      -&gt;createCommand()
      -&gt;queryAll();
  $yourCustomValues = [];
  foreach($columns as $key =&gt; $column){
      $yourCustomValues[$column['id']] = $column['instance_datetime'];
      unset($columns[$key]['instance_datetime']);
  }
  $elements = $query-&gt;populate($columns);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-22T10:40:33.717Z
Answers.Text: thanks for your assistance, is there anyway I can retrofit the relations table somehow?
Answers.UserDisplayName: amof
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-22T11:02:16.130Z
Answers.Text: Yes. You can join the table like every other table as well. Not sure where you problem is
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-22T11:18:46.723Z
Answers.Text: Im just having a hard time wrapping my head around the db design. I have a category field called genre which I want included in the results array
Answers.UserDisplayName: amof
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-22T11:24:48.220Z
Answers.Text: It depends what you need... I could explain this on Slack or here in the chat or you could create a new question because it doesn't really fit here in my opinion. Your new question is more about the structure of Craft which is quite simple but you need to understand what it joins. But it would be too much to explain in one comment
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-16T17:05:35.220Z
Answers.LastActivityDate: 2018-03-16T17:46:02.893Z
Answers.LastEditDate: 2018-03-16T17:46:02.893Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I've successfully joined a table to the elements table, however I can't can't seem to add a property so I can use it?</p>
  
  <p>Getting the error <strong>Setting unknown property when trying to join table</strong></p>
  
  <pre><code>Entry::find()
      -&gt;addSelect(['craft_event_instances.instance_datetime'])
      -&gt;leftJoin('craft_event_instances', '`craft_event_instances`.`entryId` = `elements`.`id`')
  </code></pre>
  
  <p>Thanks</p>
  
Tags: <element><join>
Title: Setting unknown property when trying to join table
ThreadText: # Setting unknown property when trying to join table
  
  (Asked by: username_0 on 2018-03-16)
  
  I've successfully joined a table to the elements table, however I can't can't seem to add a property so I can use it?
  
  Getting the error **Setting unknown property when trying to join table**
  
  ```
  Entry::find()
      ->addSelect(['craft_event_instances.instance_datetime'])
      ->leftJoin('craft_event_instances', '`craft_event_instances`.`entryId` = `elements`.`id`')
  
  ```
  
  Thanks
  
  **Tags:** element, join
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-03-16. Score: 1
  
  You can't set a property of an `element` in Craft that does not exists in the field layout, as a behavior or as a public/private attribute in the object. Craft/Yii2 will throw an exception because the property `instance_datetime` probably does not exist.
  
  In order to attach a custom value you have to either create a new `element` or you have to store this information somewhere else.
  
  ### Edit
  
  You could the following as well to fetch your values and store them into a new array
  
  ```
  $query = Entry::find();
  $columns = $query
      ->addSelect('craft_event_instances.instance_datetime')
      ->innerJoin('craft_event_instances', 'craft_event_instances.entryId = elements.id')
      ->createCommand()
      ->queryAll();
  $yourCustomValues = [];
  foreach($columns as $key => $column){
      $yourCustomValues[$column['id']] = $column['instance_datetime'];
      unset($columns[$key]['instance_datetime']);
  }
  $elements = $query->populate($columns);
  
  ```
  
  > **Comments:**
  > **username_0**: thanks for your assistance, is there anyway I can retrofit the relations table somehow?  
  > **username_1**: Yes. You can join the table like every other table as well. Not sure where you problem is  
  > **username_0**: Im just having a hard time wrapping my head around the db design. I have a category field called genre which I want included in the results array  
  > **username_1**: It depends what you need... I could explain this on Slack or here in the chat or you could create a new question because it doesn't really fit here in my opinion. Your new question is more about the structure of Craft which is quite simple but you need to understand what it joins. But it would be too much to explain in one comment  
  
  ---
  
  