Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Restricting visibility of database items


Reply


19 Posts   2126 Views

Avatar
marc79

Community Member, 65 Posts

4 May 2011 at 9:12pm

So I have decided to go back to the original method I was using, based on tutorial 5, after finding a line of code to help filter out the tracks that aren't relevant to that page - "TrackProductID=$this->ID".

However because you can't check the checkbox which is how a TrackProductID gets assigned until after you have created a new entry they are lost. I therefore need to find a way to either add in an 'OR is NULL' argument to the above line or automatically check the checkbox so that the TrackProductID is assigned by default. And then remove the checkbox so that it can't be accidentally unchecked and lost. Does that make sense?

Avatar
swaiba

Forum Moderator, 1808 Posts

4 May 2011 at 9:19pm

I'd say that the follwing is fine is all that is required to edit the data within ModelAdmin... with the has_many automatically scaffolded...

TrackAdmin.php:

class TrackAdmin extends ModelAdmin {
public static $managed_models = array(
'CDTracks',
);
static $url_segment = 'cdtracks';
static $menu_title = 'Track Admin';
}

CDVolumes.php:

class CDVolumes extends DataObject {
static $db = array(
'Volume' => 'Text'
);
static $has_many= array(
'CDTracks' => 'CDTracks'
);
}

CDTracks.php:

class CDTracks extends DataObject {
static $db = array(
'TrackName' => 'Varchar',
'TrackNumber' => 'Varchar',
'TrackDescription' => 'Text'
);

static $has_one = array(
'CDVolumes' => 'CDVolumes'
);
}

Avatar
swaiba

Forum Moderator, 1808 Posts

4 May 2011 at 9:23pm

if you want those attached, or not at all...

"TrackProductID IN (".$this->ID.",0)"

Avatar
marc79

Community Member, 65 Posts

4 May 2011 at 10:18pm

Got it! Thank you so much for all your help.

One last question. How would I add an AND statement to the query below?

"TrackProductID IN (".$this->ID.",0) AND ($AnotherID = XXXXXX)"

Thanks again.

Marc

Avatar
swaiba

Forum Moderator, 1808 Posts

4 May 2011 at 10:56pm

sure, just add the extra SQL required as in any other where clause...
joins need special attention though

Avatar
martimiz

Forum Moderator, 1135 Posts

4 May 2011 at 11:17pm

Edited: 04/05/2011 11:18pm

Reading all this I was just wondering whether you were ever going to use the same cdtrack for different cdvolumes? Since you are using a one-to-many relationship I suppose not, in which case you could just use a ComplexTableField instead of the HasManyComplexTableField (or even the DataObjectManager) that will let you create CDTracks for each CDVolume individually and then automatically add the correct page ID to the track, meaning you could even just use <% control CDTracks %> in your template?

You probably wouldn't need ModelAdmin... But maybe I just completely missed the point, in which case just forget I posted :-)

Avatar
swaiba

Forum Moderator, 1808 Posts

4 May 2011 at 11:50pm

hahe - yeah I push model admin loads :)

Mainly because I like it loads!

I do think that security is very easy for cms menu items, harder for page items. So if I wanted to have someone only have access to maintain CD data - it takes 2 seconds. Plus ModelAdmin scaffolds the entire data object, no need to create extra code (while silverSmith isn't available ;) ).

Avatar
marc79

Community Member, 65 Posts

5 May 2011 at 12:19am

Yeah. Looking at it I think, currently, the only thing I'd be using the ModelAdmin for is the CSV upload but I guess I can add this in on the product page?