Fórum

Extend user table with expando

thumbnail
Gabor Nagy, modificado 15 Anos atrás.

Extend user table with expando

New Member Postagens: 2 Data de Entrada: 04/07/07 Postagens Recentes
I read a great post form Ray Augé here: http://www.liferay.com/web/rauge/blog/-/blogs/715049
I commented the post, but I put my question here too (sorry for the duplication), maybe the community is read often :-)

Ray's example is abut creating a new table/column with expando, but I tried to extend the existing user table with a new expando column 'foo' and store a new value 'bar' there:

User user = UserLocalServiceUtil.getUserByEmailAddress(...);

ExpandoTable table = ExpandoTableLocalServiceUtil.addTable(PortalUtil.getClassNameId(user.getClass().getName()), "user_");
if(table!=null) {
ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(table.getTableId(), "foo");
if(column!=null){
ExpandoValueLocalServiceUtil.addValue(column.getColumnId(), user.getUSerId(), user.getUserId(), "bar");
}
}

Is this correct? I'm afraid the second parameter of addValue (rowid) isn't correct, but what should I write there? And what about the third parameter (classPK), is that right? classPK is the primary key of the user?
If my code/idea is correct, I would like to ask you about deleting a "parent" record. I'll try to explain what I think :-) I put the value 'bar' into expando table for the user Joe Blogs. When I delete Joe Blogs from Liferay the 'bar' value from expando tables will not be deleted. Is this right? Should I delete manually expando records? There isn't a way to do this automatically? Any idea? Or I misunderstood the whole expando-thing? :-)

Thanks,
Gabor
thumbnail
Ratnadeep Rakshit, modificado 15 Anos atrás.

RE: Extend user table with expando

Junior Member Postagens: 25 Data de Entrada: 03/03/08 Postagens Recentes
Hello Nagy,

Have you got any success with this one yet? I have a similar requirement to add City to the users table. After I read about Expendo, it seems to me as the perfect solution. But, I couln't successfully execute it yet. Please let me know how you did that!!!

Thanxxxx...
nidhi singh, modificado 15 Anos atrás.

RE: Extend user table with expando

Junior Member Postagens: 57 Data de Entrada: 29/10/08 Postagens Recentes
Hi Gabor,
I want to add new column in user table, but i am not able to do this.

so, i am using expando table in this i created user1 table, i want to map this table one field to user table.

please help me.
thumbnail
Ratnadeep Rakshit, modificado 15 Anos atrás.

RE: Extend user table with expando

Junior Member Postagens: 25 Data de Entrada: 03/03/08 Postagens Recentes
I have tried something similar to what you want to achieve. I added the users local city details in the expando table name UserExtras. I map the user table with the UserExtras table using userId of the logged in user User.

private void addUserExtras(UserExtras extras) throws PortalException,
			SystemException {

		ExpandoTable userExtrasTable = null;

		try {
			userExtrasTable = ExpandoTableLocalServiceUtil.getTable(extras
					.getClassName(), extras.getTableName());
		} catch (NoSuchTableException e) {
			if (userExtrasTable == null) {
				userExtrasTable = ExpandoTableLocalServiceUtil.addTable(extras
						.getClassName(), extras.getTableName());
				long userExtrasTableId = userExtrasTable.getTableId();
				ExpandoColumnLocalServiceUtil.addColumn(userExtrasTableId,
						"userId", ExpandoColumnConstants.LONG);
				ExpandoColumnLocalServiceUtil.addColumn(userExtrasTableId,
						"contentCityId", ExpandoColumnConstants.LONG);
			}
		}

		ExpandoValueLocalServiceUtil.addValue(extras.getClassName(), extras
				.getTableName(), "userId", extras.getClassPK(), extras
				.getUserId());
		ExpandoValueLocalServiceUtil.addValue(extras.getClassName(), extras
				.getTableName(), "contentCityId", extras.getClassPK(), extras
				.getContentCityId());

	}


Later when you need to retrive the details, you can use the tableID from the userExtrasTable and get if from the various service util classes expando provides.

I hope that helps.
thumbnail
Nagendra Kumar Busam, modificado 14 Anos atrás.

RE: Extend user table with expando

Liferay Master Postagens: 678 Data de Entrada: 07/07/09 Postagens Recentes
Hi Ratnadeep,

How does UserExtras java class will look like?. I have similar kind of requirement for LDAP extra mappings.

Thanks in advance
Tobias Marx, modificado 14 Anos atrás.

RE: Extend user table with expando

New Member Postagens: 12 Data de Entrada: 21/12/09 Postagens Recentes
1. How can you define the visibility of this data to other users?

E.g. private data such as email addresses, members-only data, friends-only data etc.... ?

How can you define who can see this data?

I assume by default it would all appear on site searches as well?

2. What if you have a workflow where data needs to be approved first, before it becomes visible?

Thanks!
Sarika Nair, modificado 13 Anos atrás.

RE: Extend user table with expando

Junior Member Postagens: 38 Data de Entrada: 06/10/09 Postagens Recentes
Hi Guys...

I have added a new field named Location in the user_ table using expando.

I am using the Directory portlet and able to display the location field for every user along with some deltais.

Currently, any user can be searched using either of the fields:
1)First Name
2)Middle Name
3)Last Name
4)Screen Name
5)Email Address

Now my requirement is that...I need to search any user using the Location field too.

Please suggest...


Regards,
Sarika
thumbnail
Christophe Cariou, modificado 12 Anos atrás.

RE: Extend user table with expando

Junior Member Postagens: 57 Data de Entrada: 01/10/07 Postagens Recentes
Hi,

I've the same need : How can we use expando attributes with the lucene search ?
thumbnail
Praveen P, modificado 11 Anos atrás.

RE: Extend user table with expando

Regular Member Postagens: 100 Data de Entrada: 21/02/12 Postagens Recentes
Hi sarika

I have added location from custom field, and it is working fine, but i am not getting where the data is getting stored because in user_ table its not included?

u got solution know, please help me out how to add location to user_ field?

Thank you in advance
thumbnail
David H Nebinger, modificado 11 Anos atrás.

RE: Extend user table with expando

Liferay Legend Postagens: 14914 Data de Entrada: 02/09/06 Postagens Recentes
expandos don't get added to any of the regular tables, they are in the expando tables.

You should not be in the database directly anyway.
thumbnail
Praveen P, modificado 11 Anos atrás.

RE: Extend user table with expando

Regular Member Postagens: 100 Data de Entrada: 21/02/12 Postagens Recentes
One table is there named as expandovalues in database(lportal default), the data which has been added in a custom fields from user is going to be stored in that table. for example if user added custom field as a location, it is going to be stored in expandovalue table under data_ column,

we can get the value from jsp tag <%= (String)user.getExpandoBridge().getAttribute("Location") %> it works fine
thumbnail
Hitoshi Ozawa, modificado 11 Anos atrás.

RE: Extend user table with expando

Liferay Legend Postagens: 7942 Data de Entrada: 24/03/10 Postagens Recentes
Yes, this is the limitation of using expando. All expando values are mixed in one table.

It's a nice feature to add fields without programming, but I don't think it's the best way to programmically add fields. I recommend not using it in program