SubSonic generates code and always filters posts
I have a table called "Users" that has a column named "deleted", a boolean value indicating that the user is "deleted" from the system (without deleting it of course, of course).
I also have a lot of tables with FK in the Users.user_id column. Subsonic generates (very well) code for all foreign keys in a similar way:
public IQueryable<person> user
{
get
{
var repo=user.GetRepo();
return from items in repo.GetAll()
where items.user_id == _user_id
select items;
}
}
While this is all well and good, is there a way to generate code in a way that always filters out "remote" users too?
In the office here, the only suggestion we can think of is to use a partial class and extend it. It's obviously a pain when there are many, many classes in the User table, not to mention it's easy to accidentally use the wrong property (User vs ActiveUser in this example):
public IQueryable<User> ActiveUser
{
get
{
var repo=User.GetRepo();
return from items in repo.GetAll()
where items.user_id == _user_id and items.deleted == 0
select items;
}
}
Any ideas?
a source to share
You need to change the following code in your ActiveRecord.tt file and restore the code:
Below is the code: #region ' Foreign Keys '
Update: I updated the code for your comment to check for the existence of a delete column and then applied the delete condition.
HasLogicalDelete()
- this function will return true if the column is "deleted" or "excluded", otherwise false.
public IQueryable<<#=fk.OtherClass #>> <#=propName #>
{
get
{
var repo=<#=Namespace #>.<#=fk.OtherClass#>.GetRepo();
<#if(tbl.HasLogicalDelete()){#>
return from items in repo.GetAll()
where items.<#=CleanUp(fk.OtherColumn)#> == _<#=CleanUp(fk.ThisColumn)#> && items.deleted == 0
select items;
<#}else{#>
return from items in repo.GetAll()
where items.<#=CleanUp(fk.OtherColumn)#> == _<#=CleanUp(fk.ThisColumn)#>
select items;
<#}#>
}
}
a source to share