In SugarCRM 7.5 Professional, how can you add custom relationship field? - sugarcrm

In SugarCRM 7.5 when you open Contacts and view a record in the Opportunities subpanel you can link Opportunity record and set contact_role (Opportunity Role) that is a custom relationship field existing only in opportunities_contacts in the database.
Now I need the same functionality working with my two custom modules with many-to-many relationship between them and access_rights as the custom relationship field.
Two custom modules were created using Module Builder and deployed: c_Accounts, c_Users.
The many-to-many relationship between c_Accounts and c_Users was created in Studio.
in custom/metadata/c_accounts_c_usersMetaData I added
5 =>
array (
'name' => 'access_rights',
'type' => 'varchar',
'len' => 36,
),
and then Quick Repair & Rebuild. I accepted the SQL query and access_rights field was added to my relationship table in database.
Next, I added into both custom modules custom/Extension/modules/{module}/Ext/Vardefs/account_user_access_rights.php
and I was able to see the field in Studio subpanels and add the column to the subpanels view.
Now, the problem is the columns are shown properly in the subpanels for both custom modules but there is no data shown from the database. How to get the data from the link table into the subpanels?
After the above is accomplished. The next thing is to be able to edit/save the field in the subpanels.

The tools (such as Module Builder) do not support this out of the box. For example, the Contact Role field you mention is implemented as part of ContactOpportunityRelationship bean within Contacts module.
If you look at how the opportunity role is defined in Contacts metadata, you'll see you need to make sure to add the right "rname_link" to the field definition. This will make sure that SugarQuery (which is used to populate Subpanels in 7.5) adds the right Join to populate your subpanel.

Related

Filemaker: How to fetch list of related entities

I'm new to Filemaker, but have extensive SQL experience.
How do I add a list of children to my Filemaker layout, if I have a one-to-many relationship (a tree)? I would like to see for my current node all its children. Later I want to filter them as well.
Showing the parent is easy via the related field. But for the reverse it appears that I need to use scripts?
In SQL, I would write:
SELECT * from Element WHERE parent = {current_id};
You set up a relationship between the tables in the relationship graph using a primary key and foreign key arrangement. Then you add a portal to the related table occurrence on your main table layout. You can add filtering in the relationship itself or in the portal afterwards.
I advice you to check out this info from FileMaker on the subject.

Rails 5.1.2 - Single Table Inheritance: No migration is getting generated

I am trying to generate scaffolding for STI implementation. I issue the following.
rails g scaffold user1 type name email
rails g scaffold member company subscription --parent user1
Every thing gets generated file except for the migration file my 'member' model.
When I try to create a member record like this
Member.create(name: "My Name", email: "myname#example.com",
company: 'Example LLC', subscription: 'Monthly Gold' )
I get this error:
ActiveModel::UnknownAttributeError: unknown attribute 'company' for Member. from (irb):1
Any ideas on what is going on?
I use rails 5 and db is postgres
The --parent option assumes that you are already all setup for single table inheritance, i.e. the parent class has a table with a type column (or whatever column you are using for this).
Since the model will be stored in the parent's table, there is no need to create a new table for the subclass, hence no migration
I got this answer similar to this question asked by someone.
To my understanding, you are on the wrong track. In single table inheritance, all the attributes must be present in the parent model table with an additional column name 'type' to indicate the type of inherited model. The column name 'type' can be changed with appropriate settings but ActiveRecord by default looks for 'type' column. You are getting 'UnknownAttributeError' error cause the parent model does not have the following column in its table. You need to write a migration to add the new columns. Hope you understand the concept of STI. For further exploration, I am providing you the link of the official guide. Hope your problem will be solved.
http://edgeguides.rubyonrails.org/association_basics.html#single-table-inheritance

Symfony2: Collection of dropdown select lists for a many-to-many relationship

The objective:
Having a many-to-many relation be displayed as a dynamic list of select inputs(single choice dropdown list)
User arrives on page with a single select field (multiple = false) populated with persisted entities and add/remove buttons. By clicking the add button, a new select field with the same options appears below the first, which adds a new entry in the M2M relation. By clicking remove the field disappears and the entry should be removed.
The model:
Two entities: User & Manager. A User has exactly one "special" Manager and unlimited normal Managers.
Managers manage unlimited users.To model this I have created two relationships for which the user is the "owner" (not sure how to translate this)
ManyToOne specialManager
ManyToMany normalManagers
I haven't created a many to many relationship with attribute "special" because the requirement is exactly one special manager and I wasn't sure if Symfony/Doctrine would cause problems down the line.
What I have:
I can display a multiple select field with the existing entities using Entity field type, as per the documentation. Functionally this is what I need, visually it is not.
I can also use the Collection field type to display a single text field, and add or remove more with JS, as per the documentation. Visually this is what I need, but The text fields (entity attribute) need to be replaced by choice field.
The question:
Before I continue digging, is there a simple way to achieve this list of select tags?
For anyone else who may eventually need a dynamic list of select fields:
I initially solved this issue by detaching the field(s) in event listeners, and handling the display/submission manually in the controller.
However I wasn't satisfied with this clunky solution and when I encountered the same need I used a second solution: creating an intermediary entity xxxChoice (in this case ManagerChoice) which is Mto1 inversed related to User and Mto1 related to Manager. Then by creating a ManagerChoiceType form with "Manager" entity field type I was able to easily display my collection of dropdown select lists.

How to handle autopopulated selects (from oneToMany relation) in Symfony form?

I have a ProductCategory class that has a parent and some children, properly annotated using Doctrine.
Then I have a ProductCategoryType (form class) that I use to render the html form.
Doctrine does its magic and creates a select box for parent which consists of previously added categories.
My problem: How to I prepend a default option (say '0' => 'No parent category') and how do I remove a particular category from list (ex: the currently edited category, so user can't select the very category to be its own parent)?
This can easily be achieved by using DataTransformers.
You can find more information in the documentation chapter How to use Data Transformers.

Dynamic Form Generation with Symfony2

The scenario is pretty simple, I want to enable adding product attributes in my webhop. So, I have product table which holds product information (price, description...), attribute table which defines all possible product attributes (color, weight, power...), product_attributes table which connects this two and holds actual attribute value (red, 25kg, 51w...).
I would like to enable product form to enable adding/editing this attributes (attribute set is defined in attribute table).
I tried using collections, but that allowed me to only edit existing product attributes, not to add new.
I also experimented with event subscribers, but everything I add does not fit in my Product entity, it is just not that flexible to accept anything, it asks for attributes.
Is there any good way to solve this problem?
You can accomplish what you want with Embedding Collection of Forms, and using some jQuery magic to make it pretty.
It's explained in detail in the guide. With collections you need to use :
'allow_add' => true, 'by_reference' => false,
to allow the users to add new attributes.