Yii relations cgridview - yii

I am using Yii User Management along with my tables.
The relation between User and Profile table is as per the extension.
I am using a table called reservation which contains user_id as a foreign key reference to id field in the User table. The relation to the user table is named user.
In the admin.php of the reservation controller I want to display the First name stored in the profile table.
My query is how can I display the firstname of profiles table in gridview using $model->search() of reservation model.
Code currently being used is :
array(
'header'=>'User',
'name'=>'user_id',
'value'=>'$data->user->username',
),

User is model is related with Profile model using the profile relations
so try this
array(
'header'=>'User',
'name'=>'user_id',
'value'=>'$data->user->profile->first_name',
),

Related

Multiple Role Database Design

I recently had this problem in designing a SQL database.
I want to create a database for a school, and of course not all users have the same role or privileges.
For example, there are teachers, headteacher, students and parents.
If I put all those in the same table and put a role column the table, then I can't be free to put any other columns for a specific role
like I can't add a grade column for student because the other roles don't have grades.
Also I can't put them in separate tables because in the log in I can't specify the role for this user and go to his table .
What is the best way to do something like this?
Use polymorphism on the user table.
Create a user table with basic authentication and common information like email and credentials. Now create 2 columns authority_type, authority_id (naming can be changed).
Now for every type of new role or privilege, create a table.
For e.g. In your case, there will be a table for the teacher, headteacher, student and parent. All have separate sets of attributes.
Whenever saving a user record, you'll use its authority_type and its authoriy_id ( record foreign key of that other table ).

How to design database where users can have arbitrary relationship to another user?

I'm using PostgreSQL and new to databases in general.
Say I have a table of users, and I want to let users define that they are another user's wife/husband/whatever they want. Assume that a user can say another user is their grandma, and that user can say the other user is their "grandson in Maine" (i.e. it is directed).
Do I create a table for users, and another table that looks something like:
CREATE TABLE user_relationships (
user0 INT REFERENCES app_user(id),
user1 INT REFERENCES app_user(id),
relationship VARCHAR(100)
);
to hold all of the relationships separately, or is there a better way to link both the other user and the defined relationship in the user table?

How to link User Data in aspnet_Users and Users tables in DotNetNuke

I'm creating a module for DNN 7.3.4. Another bought module creates new users. I need to display a list of those users in my module using an SQL statement. However the other module creates them in the table aspnet_Users and also adds their details into the Users table.
I cant see how I can link the records in both tables as the userid in the aspnet_Users table takes the form of "6c9c37b9-0a9a-4394-aad5-715e63681024" whereas the Users table UserID field contains "1".
The link there is the "username" field in both tables.
If you are trying to display users from your own module, you should only look at the DNN Users table, and UserPortals, I would ignore everything in the ASPNET_ tables, just let DNN maintain that link.

Is user group table required when using Yii authManager?

if I am using Yii's authManager, am I still required to create a user group table? Correct me if I'm wrong, if we're using authManager and RBAC schema, we create roles and assign tasks to it. We then assign roles to a users.
In that case, do we still need a group table and have a FK in the user table that references group table's ID column?
Thank you.

use of views for validation of an incorrect login-id or an unidentified user

I read this on msdn:
Views let different users to see data in different ways, even when they are using the same
data at the same time. This is especially useful when users who have many different interests and skill levels share the same database.
For example, a view can be created that retrieves only the data for the customers with whom an account manager deals. The view can determine which data to retrieve based on the login ID of the account manager who uses the view.
My question:
For the above example , i would have to have a column named Userid/LoginId on my table on which the view is created so that i can apply a check option in the view for this column. and then if a user with a name not in that column tries to enter data , then he/she is blocked.
Yes, you are right. You should
add a column with the user's login or database user name (say you call it username),
each row should have username populated with the login or database name of the person who is allowed to see that row
you can then build a view where you use the builtin functions SUSER_SNAME() (for logins) or USER_NAME (for database names) in your WHERE clause to filter only the rows the user is allowed to see
See Granting Row-Level Permissions in SQL Server (ADO.NET).
You don't have to add a column to the table: it could be more appropriate to instead add a new table to model the relationship.
There's a deisgn rule of thumb that states a table should model an entity or a relationship but not both. Let's say the table in question models the companies a customer owns (i.e. an entity table) and the business rule states the the account manager can only see companies relating to customers he looks after.
Is account manager an attribute of a company? No, so account_manager should not be a column (attribute) in the Companies table.
Is there a direct relationship between account_manager and a company? No, so a relationship table between is not due here (because the relationship is indirect).
Rather, the direct relationships are between account manager and customer, and between customer and company respectively. There should be two tables whose sole purpose is to model these relationships.