Answers.Body: <p>I think what you're asking is how to define the relationship using Active Record in the other direction - going from Craft's <a href="http://buildwithcraft.com/classreference/models/AssetFileModel" rel="nofollow">AssetFileRecord</a> to your plugin's EstateRecord.</p>
  
  <p>And the answer is that you can't without hacking the AssetFileRecord and manually adding a BELONGS_TO relation back to your Estate Record.</p>
  
  <p>You're going to be much better off ditching records and active record for this all-together, I think.  Have your service layer use the <a href="http://www.yiiframework.com/doc/guide/1.1/en/database.query-builder" rel="nofollow">Query Builder</a> <code>craft()-&gt;db-&gt;createCommand()</code> directly, then you can join in any data you want from any tables outside of the context of active record.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-02T11:45:11.470Z
Answers.Text: Thanks for your answer, it helps me a lot! I will post my solution later.
Answers.UserDisplayName: phaetons
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-01T22:03:35.270Z
Answers.LastActivityDate: 2015-04-01T22:03:35.270Z
Answers.UserDisplayName: Brad Bell
Body: <p>I defined an <code>estateRecord</code> in my Plugin. Every estate has a set of images that i want to import from a zip file directly via <code>assetsService::insertFileByLocalPath()</code>.</p>
  
  <p>In my <code>estateRecord</code> I defined a relation:</p>
  
  <pre><code>public function defineRelations()
  {
      return array(
          'assets' =&gt; array(static::HAS_MANY, 'AssetFileRecord', 'id'),
      );
  }
  </code></pre>
  
  <p>Is that correct?</p>
  
  <p>Now i'm stuck to define a 'asset'-field in the estateModel to access the image-sets.</p>
  
  <p>I just find a solution to define the Attribute for one assetId but have no idea how to define the Attribute for the related set of assetIds.
  How can i do this?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-01T12:34:06.433Z
Comments.Text: No one with a hint for me?
Comments.UserDisplayName: phaetons
Tags: <assets><plugins><relations>
Title: How to create a relation to multiple assets in my Plugin Model/Record?
ThreadText: # How to create a relation to multiple assets in my Plugin Model/Record?
  
  (Asked by: username_0 on 2015-03-27)
  
  I defined an `estateRecord` in my Plugin. Every estate has a set of images that i want to import from a zip file directly via `assetsService::insertFileByLocalPath()`.
  
  In my `estateRecord` I defined a relation:
  
  ```
  public function defineRelations()
  {
      return array(
          'assets' => array(static::HAS_MANY, 'AssetFileRecord', 'id'),
      );
  }
  
  ```
  
  Is that correct?
  
  Now i'm stuck to define a 'asset'-field in the estateModel to access the image-sets.
  
  I just find a solution to define the Attribute for one assetId but have no idea how to define the Attribute for the related set of assetIds.
  How can i do this?
  
  **Tags:** assets, plugins, relations
  
  > **Comments:**
  > **username_0**: No one with a hint for me?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-04-01. Score: 1
  
  I think what you're asking is how to define the relationship using Active Record in the other direction - going from Craft's [AssetFileRecord](http://buildwithcraft.com/classreference/models/AssetFileModel) to your plugin's EstateRecord.
  
  And the answer is that you can't without hacking the AssetFileRecord and manually adding a BELONGS\_TO relation back to your Estate Record.
  
  You're going to be much better off ditching records and active record for this all-together, I think. Have your service layer use the [Query Builder](http://www.yiiframework.com/doc/guide/1.1/en/database.query-builder) `craft()->db->createCommand()` directly, then you can join in any data you want from any tables outside of the context of active record.
  
  > **Comments:**
  > **username_0**: Thanks for your answer, it helps me a lot! I will post my solution later.  
  
  ---
  
  