Hi,
I’m a newbie at yii so please be patient I’ve been reading documents and posts for days now and just can’t seem to make any progress so I thought I’d ask the forum.
I’m trying to create an application (based on the basic application) that has a db schema something like this:
Many Users can belong to an Organisation
An Organisation has many Datasets
A Datasets has many Filesets
A Fileset has many Files
The User, Organisation, Datasets, Fileset, Files are all tables with the correct FK relations setup.
I’ve got GII to spit out the Models and CRUD correctly. The models have all nice relations setup thanks to GII. For example:
User has
/**
* @return \yii\db\ActiveQuery
*/
public function get Organisation()
{
return $this->hasOne(Organisation::className(), ['id' => 'organisation_id']);
}
Organisation has
/**
* @return \yii\db\ActiveQuery
*/
public function getDatasets()
{
return $this->hasMany(Dataset::className(), ['organisation_id' => 'id']);
}
Dataset has
/**
* @return \yii\db\ActiveQuery
*/
public function getFilesets()
{
return $this->hasMany(Fileset::className(), ['dataset_id' => 'id']);
}
I’ve got the Login Form linked to the User table following http://www.yiiframework.com/doc-2.0/guide-security-authentication.html
But where I’m stuck is in the next part I’m trying to achieve:
-
When a User is logged I want him to be able to go to organisation/index and edit only his organisation details. As expected at the moment when I go there I see all organisation listed and can edit any.
-
When a User is logged in I want him to be able to go to datasets/index and edit only the datasets that his organisation has created . As expected at the moment when I got there I see all the datasets that any Organisation has created.
-
Finally I want a User to be able to go to fileset/index and edit only the filesets that are part of the datasets that his organisation has created. As expected at the moment at the moment I see any filesets that are part of any dataset that any organisation made.
I’ve looked around at heaps of examples and I see people (e.g) creating WHERE statements and performing JOINs back to different tables but I feel like all these are reinventing the wheel…each model already knows how its related to other models via the function that GII created. So isn’t there an easier way to make this happen?
For example:
-
is there a way for to apply a filter that uses User->getOrganisation()
-
is there a way to apply a filter that uses the organisations getDatasets() to only show that users->organisations->datasets?
-
is there a way to apply a file that uses a selected datasets getFileset() to only show that users->-organisations->datasets->filesets?
Any help would be appreciated to point me in the right direction.
Thanks