Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Object inside another Object?
Hello everyone, i'm trying to understand how could i develop an
object that stores other objects.
To understand better, I use a
form to get some data from the user and after I store these datas in
an object and I display all datas in another page.
Now i would like to give to users the possibility to leave a comment and I was thinking to store the comments like a new object inside the original one. Is it possible?
Thanks everyone.
Well, not an object inside of an object, but you can define relationships to objects and then leverage the relationship to have a similar concept of one object containing another.
Unfortunately at this time Liferay only supports a one to many or many to many relationship between objects, although we have been pushing the team to introduce a one to one relationship. A one to many can simulate this if you add actions to prevent adding multiple children in the one to many relationship, but I (and others) feel this is a bit hacky. So one to one is on the roadmap, we're just not sure when it will be delivered.
Thanks everyone for the reply.
Hello,
You can not add one object to another object, but you can do mapping between the objects
You just need to create one-to-many type mapping from the main object to the comment object
Once you do the mapping, you can add one more tab to the VIEW section and add a view of the relations
Let me know if you want step to step guide for this
Thanks, I think i set it up well but a step to step guide would be very appreciated, last thing, after I have the relationship how can i display it in a new page? Because I was trying to display it with a form + display content but when I try to map a Form Field to the relationship it doesn't work because it can't find the relationship but it find only normal fields.
Thanks.
Powered by Liferay™