How to create a relation to multiple assets in my Plugin Model/Record? 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' =&gt; 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?
I think what you're asking is how to define the relationship using Active Record in the other direction - going from Craft's AssetFileRecord 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 craft()-&gt;db-&gt;createCommand() directly, then you can join in any data you want from any tables outside of the context of active record.