sonata admin one-to-many and many-to-one display list - sonata-admin

I have a project about nurse and patients. Nurse goes around and visits patients. The problem that I'm facing is that the nurse wants to see a list of all the visits they did for a patient.
I do have two admin pages, one is the patients admin (allows to create/edit patients) and another one that allows to log visits. Within the visit you select the patient. From the patient list, how can I list all of the visits a nurse did for a patient? and further more, allow to click an add button to log a new visit.
I don't have code to show, but if any of you can point to some documentation, or sample code, will be much appreciated.

On the patient edit page you could do the following. Assuming your entity is called something like VisitLogs. You can add the following to configureFormFields
$formMapper->Add('VisitLogs', 'sonata_type_collection' ['type_options' => ['btn_add' => true]], ['inline' => 'table', 'edit' => 'inline']);
This should display a table with the Visitlogs based on the patients (if the ORM is correctly setup) and shows a add new button.
I hope this somewhat helps you a little bit further. More information.
Note This is for the one-to-many relation. I'm guessing for the many-to-one relation you should use sonata_type_model not sure about that though.

Related

I have one contact in SF that works for one customer, but is now helping with another customer...how do I add her to the second customer's contacts?

I have a contact in SalesForce, she works for a PE group, and is attached to one customer, but is also helping answer questions for another customer. I tried to add her in the second customer's contacts, and it said she was a duplicate, but I can't figure out how to attach her to both accounts. Any direction on where I can learn to do that? Thank you!!
Contacts can be connected to accounts directly (parent-child, via Contact.AccountId lookup) and indirectly (many-to-many, AccountContactRelation). It's useful when contact has multiple functions, for example being Director in 1 company and VP of Sales in another.Check the page layout, you might have to add a related list.
https://trailhead.salesforce.com/en/content/learn/modules/accounts_contacts_lightning_experience/understand-account-and-contact-relationships-lightning might be a good start

can we show Account records on Contact?

On Account object we have a related list called contact.If we want to add contact we can use Contact related list. then contact related list will created. But on the contact i could n't find the Acccount name in Account related list on Contact. Both Accounts and contacts are m-m relationship
Your question is bit weird. And it's not really programming-related. If my answer doesn't help you - try asking again at https://salesforce.stackexchange.com/
The default setup in Salesforce is that Accounts and Contacts are in 1:n relation. So you have related list of 0,1 or more Contacts under Account. But when you're on Contact there's only 1 Account to choose from. And it's the "Account Name" field, a lookup (foreign key), not a related list with exactly 1 item on it.
You're 1 click away from viewing the Account. If that's not enough, if you really want to display Account data on Contact - there are options such as formula fields or adding "record detail" component to the page and making it use Account Name instead of this Contact. You can see it on the right side in my screenshot:
When you make new Contact you can select existing Account or click "New" in the lookup and create one on the fly. But relation is still 1:n, A contact will have 0 (possible but an edge case and generally bad idea) or 1 account.
Then there's a special table called AccountContactRelation. It's used to model "one guy working in multiple companies, for example being director in company XYZ small local branch and at the same time - head of accounting in company XYZ headquater". If you want that, a real m:n relation - you might have to enable few things in Setup and configure your Salesforce like this training course: https://trailhead.salesforce.com/en/content/learn/modules/admin_intro_accounts_contacts/admin_intro_accounts_contacts_relationships
But on the contact i could n't find the Acccount name in Account
related list
So... if you already have the "Contacts to Multiple Accounts" enabled and added to page layouts and stuff - then perhaps it's as simple as checking the Contact page layout and editing the related list to include Account Name. But I have a feeling you skipped few steps on the way.

Generating form for associated data on through table

I have a hasMany through schema for volunteers who make up teams. It's like this:
Volunteers belong to many Teams
Teams belong to many Volunteers
Both through a table of Memberships.
The reason why I used a through table is because I need to select certain volunteers as team leaders in certain teams they participate in. The field is boolean --TINYINT(1)-- and part of my join table. This is similar to CakePHP documentation's example of starred, I assume, on which an element is selected as highlighted.
Now, I am wondering on how to select volunteers as team leaders on an form in a way that I can load the list of associated volunteers (or during the selection page) and then mark a checkbox for 'team leader' for each name, or a widget that allows me to select only from the reduced list of volunteers already members of this team. So far, I have decided to leave the associated volunteer selection in the team edit page:
<?php echo $this->Form->control('volunteers._ids'); ?>
Which is pretty easy and straightforward, but from here, But I can't seem to find a way to generate the selection box for the already-reduced list of volunteers. I've found everywhere for an example of this, but I probably don't have the skill level to make a good search, as I'm not sure how to word my question, I guess.
Can you please help me out? I understand that a through table has a belongTo relation, but I don't know whether CakePHP generates the list of inputs for me, or whether I need to create a loop (which would mean that I need to add something on the controller to do so).
Thank you!

Simple Database Schema for a tech blog

I am building a simple tech blog and this is my database.
Because I don't really have a lot of experience I am looking to get some feedback if its an OK schema.
I will have 5 categories: Computer, mobile , laptop , tablet and General.
For users I will only have an admin to begin with and maybe I will add users later.
User will only be able to comment/share on the posts nothing more.
Only admins will be able to create posts etc.
Guests will only be able to browse the site and share posts.
I would like to add a feature to be able to count how many shares have been made for a specific post but later.
Also I might add sub categories to each category (for this I think that I need another table to track those).
Any help is appreciated, thanks in advance.
In my view, you should add a comments table; in your database a Post can have only one comment.
Comments should have this fields at minimum: id, body, post_id, user_id, because they belong to a Post and to a User.
In the posts table add fields: user_id and category_id because each post belongs to a User and to a Category; and remove the comment field because a post can have many comments.

CakePHP 2.1 HABTM Not Getting Associated Info

I have a question that's been bugging me all afternoon:
I'm making a guitar gear site, so I am using a gear items table, a user table, and gear-to-user bridge table. That is, a user can own multiple items and items can belong to multiple users. So HABTM.
An item belongs to a brand (e.g. Fender - Stratocaster), so I set up a belongsTo relationship in the item model as well as a HasMany relationship in the brands model. When I check the output in the items controller, the gear and its associated brand's data is all there as it should be.
The user control panel (and similar areas) basically list all of the user's owned items. After setting up the HABTM relationship between users and items, I checked the controller's output. While the item's information and the bridge table information all appeared, the item's associated brand information did not. The results should essentially be a list of items, including brand information, as if it were "where user_id = x". Instead, it seems to only be grabbing the item information and none of its relationships.
Is there something I'm missing or a dumb mistake? Thanks.
Did you consider setting/changing the recursive attribute when performing find() on the User?
The higher recursive is set, the deeper associations will be found.
An alternative might be to use the Containable behavior on User:
$this->User->find('first',array(
'conditions'=>array('User.id'=>1),
'contain' => array('Item'=>array('Brand'))
));
Set the recursive level up or you can use ContainableBehavior

Resources