okay so essentially I want to add my current user that is logged into a multi reference field of another user once they press a follow button on that users profile.
So if I want to follow your account, I am trying to use insertReference() to insert a reference of my profile item into the followers field in your item.
Here’s my current code.
I iterate through each item in the repeater and set its individual components to build the individual users “mini profile”
itemdata refers to the current item.
$w(“#repeater2”).forEachItem(($item, itemData, index) => {//repeating user
let belt = itemData.belt;
let a=" | | | | “;
if (itemData.stripe===“0”){ a=”`````````“;}
else if (itemData.stripe===“1”){a=”|```````";} **else if** (itemData.stripe==="2"){a="
| |`````“;}
else if (itemData.stripe===“3”){a=”| | |```";} **else if** (itemData.stripe==="4"){a="
| | | |`";}
here i’m setting their profile up. nothing special
$item(‘#repeatedName’).text=itemData.name;
$item(‘#repeatedProfilePic’).src=itemData.photoProfile;
$item(‘#repeatedContainer’).src=itemData.photoCover;
$item(‘#repeatedBoxBelt’).style.backgroundColor = session.getItem(belt);
$item(‘#repeatedStripes’).text = a;
$item('#repeatedFollowButton').onClick((event)=>{
when the button is pressed i call the following function which i have created and i pass in the current profiles itemData
followUser(itemData);
});
});
export function followUser(itemData){
//must add current user(logged in user) to selected users followers
//inserts a reference to the item with ID of the current user in the followers field of the item in the USER_ProfileData collection with the ID of the selected user(the one the current user wants to follow).
wixData.insertReference("USER_ProfileData", "followers", itemData._id, wixUsers.currentUser.id)
.then( () => {
console.log(">Reference inserted ");
} )
. **catch** ( (error) => {
console.log(error);
} );
}
When I press the follow button I am getting the following printed to the console.
Error: Provided relationshipAttribute [followers] is not a multi-reference field.
The field is in fact a multi reference field…
just in case you want to look around. HERES THE LINK!
www.grapplehub.net
THIS PROBLEM HAS BEEN BUGGING ME FOR A LONG TIME!! ANY ADVICE IS VERY MUCH APPRECIATED!