Hi guys! So, I know there’s a lot of MLM haters, and is not really MLM as it only has 4 tiers, is basically a long referal system.
Problem is, I’ve built it with only a single field, where each user record has a “referred-by” field.
Of course this works great for the first 2 tiers, but its becoming a problem to query/search that. Did you ever had to deal with something like this?
If so, how did you call it to display the tiers?
Right now I’m trying a simple "do a search for: users: where the refered-by is current-user; Then tier 2 is do a search for: within a search for: for that first repeating group users, and then you already this will become a problem by tier 3.
Yeah, it’s one of Bubble’s major limitations that you can’t do proper recursive queries…
But if you have a known number of tiers (i.e.4), doing something similar to what you’re doing is no problem at all.
To simplify it, use 3 RGs as variables to hold each tier’s Users, and a regular Group as a variable to hold the top tier User. e.g.
var1 - topTierUser (regular Group) = The Top Tier User
var2 - tier2Users (RG) = Search for Users who’s referred-by is topTierUser
var3 - tier3Users (RG) = Search for Users who’s referred-by is in tier2Users
var4 - tier4Users (RG) = Search for Users who’s referred-by is in tier3Users
Thank you so much for your time, @adamhholmes . I indeed am doing that way, with a small modification. That was my first version, but boss says there will be people with dozens of thousands of referrals, which should freeze up if I have the rg show up all records of rg2, for the rg3 to work that way;
Because of that, I’ve changed to searches within searches, which is not working well too. So, first version was just like you mentioned:
And then the current version is like this:
var1 - topTierUser (regular Group) = The Top Tier User
var2 - tier2Users (RG) = Search for Users who’s referred-by is topTierUser
var3 - tier3Users (RG) = Search for Users who’s referred-by is in Search for Users who’s referred-by is topTierUser
var4 - tier4Users (RG) = Search for Users who’s referred-by is in Search for Users who’s referred-by is in Search for Users who’s referred-by is topTierUser.
And this is also not working well. When showing up, I’m doing paginations of course, but still, even search for:count: is messing it up.
I’m thinking I’ll have to rebuild the DB structure somehow to query it differently…
Well those are exactly the same thing (it’s just much easier to manage using an RG, or custom state, as a variable, rather than using a nested ‘search for Users’ expression… but there is no difference between them).
but if I understand your question correctly (as in, your trying to only show a small number of the potentially thousands of users in this hierarchy), your best bet will be to switch to an external database, where you can do recursive queries directly on the database.
But, if that’s not an option, then you’ll probably have to use some list fields, or at least some joining tables, to establish the ‘hierarchy’s’ as distinct entities in your database.
One option is to store a list of all ‘upline’ referrers on the User (there will only be 4 at most), rather than the other way around, but it can get complicated to maintain, especially if the referrer of a User can change.
you are absolutely right! I was having an issue with my interface rather than being the nested searches. I just tested it pulling texts and done. Really a brain fart today hahah.
I was thinking earlier on using Algolia as source for this since chief has already bought it, but they’re such a pain to implement properly I gave up. Probably a great plan B if my current setup fails.