Again I seem to be stuck on the database logic.
I have a data type called Company, which stores all the company information for a user.
I want to display this information as shown below, but for whatever reason I cannot get it to show any information, even though it is there in the database. I am not sure why I’m struggling with the DB concepts so much, it seems like every time I progress I then hit another frustration in the setup (which is not bubbles fault).
Hi there, @deeknee… you have privacy rules applied to your Company
and User
data types, and those rules are likely causing the issue. To see if that is the case, delete the privacy rules and see if the data shows up… you can always add rules once you have a better understanding of how they interact with your app.
Oh, one more thing… the search you are showing in your third screenshot probably shouldn’t be a search. Current user's Company Name
(assuming a user is logged in at that point) should get you what you need there.
Hope this helps.
Best…
Mike
1 Like
Hello again .
This is what I was doing originally but it didn’t seem to work, not sure if I’ve setup the relations incorrectly, but it still shows blank!
Did you check the privacy rules? You probably have it set up so that only the user who created a company can see that company’s information. As I mentioned, you might consider deleting the privacy rule on the Company
data type just to see if you can get the data to show up. If the data appears, then you know the issue is related to how you have the privacy rule configured.
Whoops sorry forgot to mention that I did delete the privacy rules and the issue persists. Not sure if it’s a relationship configuration issue?
You are sure there is data in the database and you are logged in as the correct user?
Also, given our previous interaction, I happened to notice your Users
field on the Company
data type is not a list. If you want to have a list on the Company
data type of the users who belong to that company, you are going to need to delete that Users
field and create a new one that is a list (there is a checkbox to make a field a list).
I’ve made the change to the user field under the Company Data Type as mentioned. There is information in the Database as well, i’ve attached another screenshot. The lined out parts are a personal email, but are exactly identical.
In order for Current user's Company's Company Name
to work, the Company
field on the User
data type has to be populated for that user. In your second screenshot, the user’s Company
field is empty, so that’s why it is not working.
Just food for thought… if you haven’t done Bubble’s tutorials, I would suggest you work through them. They are a great way to learn the basics of Bubble, and they help to set a solid foundation when it comes to the knowledge you will need to be successful with Bubble.
Thanks! I also did this and learned how to do this via the bubble documentation. But every time I populate it with the users email, it just removes the information, which is odd as well.
Is this because the company attribute under user should be a user field?
1 Like
No, the Company
field on the User
data type should be a company (which it is). That field needs to be populated with the company that the user belongs to.
In this case the email wouldn’t suffice due to some sort of clash and I would need to use another field?
I’ve tried everything, at this point I can only assume I have some broken database of some sort.
How are you associating a user to a company? Do you have a user interface for that or are you just doing it in the database for now. Just to see it work, try the following:
- In your last screenshot, click the Primary fields button and change the primary field for Company from unique id to Company Name.
- Edit the user record you are showing in your last screenshot, and in the
Company
field, start typing the name of the only company in your database. Select the company and save the record.
At this point, the user is now associated with the selected company, and when you log in as that user, you should see the company name.
1 Like
Right now I’m doing it in the database to understand how the logic will work. Then I’ll make sure a workflow repeats that logic to enable companies to be associated to users etc.
But amazing, this has worked. My thinking is why this did not work before with the unique ID? Because now Company Names will need to be unique in order to avoid clashes.
Do you mean the unique ID of the company? If you tried to put that ID in the Company
field prior to changing the primary field to Company Name, it should have worked. The only reason I suggested changing the primary field is because most folks who are relatively new to Bubble don’t understand the ID’s right off the bat, so I figured it would be easier to work with the company name in the db.
The above being said, company names will not necessarily have to be unique because they are all separate things in the Company
data type that have unique ID’s.
Yes that’s right, I thought the logic worked as: User > creates company on sign up > user is assigned to company on the company data type > the unique ID is the primary field so the company is associated with that user that created it.
It makes complete sense what you’re saying now. If I wanted to do ID, I guess I would need to do that within the workflow, assigning the unique ID. But if that’s not needed then I can use company name. I think what is throwing me off is the SQL logic of having a primary key which is what is being skipped over, but the documentation online doesn’t really explain the logic, it just says “Do X to achieve Y”. I struggle to grasp stuff without full context or understanding. You’ve been amazing here by the way, appreciate this a lot.
1 Like
My pleasure, @deeknee… happy to help.
Yup, it’s just like you said… a user who creates a company is associated to the company via the Created by
field on the Company
data type. If you want to associate a company to a user on the User
data type, you have to make that association via a workflow by populating the Company
field on the User
data type with the appropriate company. Note that the association will be made with the company’s unique ID, regardless of whether or not you are showing the company name in the database.
1 Like
So why wouldn’t Current users's company's description
not work in the first place? Because in theory is it not just taking the current user, searching the company data type and the description assigned? (Last question I promise).
Nope, it sure isn’t.
The reason that didn’t work is because the Company
field on the User
data type was empty. The expression Current user's company's description
means look at the Company
field for this user (again, the Company
field on the User
data type) and go get the associated company’s description. You could also have accessed that company’s description with the expression Search for Company's:first item's description
with a constraint on the search of Created by = Current User
, assuming the user is the creator of the company, of course.
I see, this actually makes a lot more sense logically in terms of speed and performance when running such search queries.
Really well explained and plugs a huge gap in my knowledge. Thanks again for this, clearly you have a lot of great experience with bubble.
1 Like