So I have two objects. User and Tag.
A single User record can have an unlimited number of tags.
A single tag record can have only one user. But a Tag object can have an unlimited number of users.
So we have a many to many relationship, with a table joining them. The table already exists (tag_user) so I need to specify that.
When I get a user, it should get all of his tags as well, like wise when getting a tag it should get all the users. except that might not always be a good idea. What if I have 10,000 users with the tag 'Public' I might want to get that tag without getting all the users who have that tag. alsoIf i'm getting a list of users and they all have the 'Public' tag, it shouldn't the tag shouldn't pull that list of 10,000 for each user in my list. It should only pull it once, and thats only if I ever request it.
So I need to do some lazy loading. Say it only gets the related object if it's requested. So if I get a list of users, it'll just fill out that list. If I access the tags on one of the users, then it'll go and fetch his tags.
So first things first:
Create Many to Many relationship, if you access the related object, then it goes and gets it.
No comments:
Post a Comment