How To set associated data into zend form in ZF2?
I am getting this error :
Zend\Form\View\Helper\FormSelect does not allow specifying multiple selected values when the element does not have a multiple attribute
set to a boolean true
after using the below code.
$data = Entity Object[
'name' => 'test'
'email' => 'test#test.com',
'type' => Object[
'id'=>1,
'type'=>'admin'
]
]
when I used for set data
$form->setData($data->toArray())
it gives me above error.
I am using ZF2, Doctrine2 , MysQL
Please help me to fix this.
Related
Is there a way to exclude certain submission values from being saved to the submissions table in Drupal? I would like to send a complete set of all submission values per submission via email, but I would like to exclude personal data like email-addresses and the like from being saved to the table. Is there a way to accomplish that?
You can use Drupal's webform submission exporter service to export submission data and also exclude unwanted columns during export. Something like this:
$submission_exporter = \Drupal::service('webform_submission.exporter');
$export_options = $submission_exporter->getDefaultExportOptions();
$export_options['excluded_columns'] = [
'uuid' => 'uuid',
'token' => 'token',
'webform_id' => 'webform_id',
'completed' => 'completed',
];
$submission_exporter->setWebform($webform);
$submission_exporter->setExporter($export_options);
$submission_exporter->generate();
$temp_file_path = $submission_exporter->getExportFilePath();
In my extension I have two models: the parent model being research groups of a doctoral program, the child model being application rounds (with opening and closing dates). In an intermediate table I store the relationship between the two for research groups participating in application rounds. The application rounds can overlap with certain groups participating in two parallel rounds. That is the reason why I needed to make it an m:n relation. I made it all work using the official documentation.
Whereas I can select multiple application rounds in the research groups form, I additionally want to make the backend form of the application rounds show a list of all groups to select from.
I found the information on inline fields which shows a bidirectional use – but I am struggling translating this into my extension’s situation.
Note: I do not want inline edits, really only selectCheckBox lists on both sides.
The Groups domain model contains the following property:
/**
* #var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Myvendor\Researchgroups\Domain\Model\ApplicationRounds>
*/
protected $applicationRounds = NULL;
persisted in the database by application_rounds INT(10)
The Groups TCA contains the following definition:
$GLOBALS['TCA']['tx_researchgroups_domain_model_groups']['columns'] = [
'application_rounds' => [
'label' => '' . $locLang . 'groups.recruitingSelection',
'config' => [
'type' => 'select',
'renderType' => 'selectCheckBox',
'foreign_table' => 'tx_researchgroups_domain_model_applicationrounds',
'foreign_table_where' => 'ORDER BY tx_researchgroups_domain_model_applicationrounds.date_open DESC',
'MM' => 'tx_researchgroups_groups_applicationrounds_mm',
'eval' => 'int',
],
],
]
How do I add a corresponding select list to the ApplicationRounds model? Do I have to add a property there as well, persisted in the database – even thought that would be redundant?
you need to set mm-opposite-field:
If you want to make a MM relation editable from the foreign side (bidirectional) of the relation as well, you need to set MM_opposite_field on the foreign side to the field name on the local side.
[edit by original questioner] see next answer for the full code based on this answer
Here’s the full working code I added following the hints in Bernd’s answer:
ApplicationRounds TCA (child model)
$GLOBALS['TCA']['tx_researchgroups_domain_model_applicationrounds']['columns'] = [
'researchgroups' => [
'label' => '' . $locLang . 'researchgroups_applicationrounds.recruitingGl',
'config' => [
'type' => 'select',
'renderType' => 'selectCheckBox',
'foreign_table' => 'tx_researchgroups_domain_model_groups',
'foreign_table_where' => ' AND tx_researchgroups_domain_model_groups.hidden = 0 ORDER BY tx_researchgroups_domain_model_groups.last_name ASC',
'MM' => 'tx_researchgroups_groups_applicationrounds_mm',
'MM_opposite_field' => 'last_name',
'eval' => 'int',
],
],
]
(don’t forget to add researchgroups to $GLOBALS['TCA']['tx_researchgroups_domain_model_applicationrounds']['types'][1])
And add a field to the database table of the child model:
researchgroups INT(11) NOT NULL DEFAULT '0',
I did not add researchgroups to the domain model though.
Dealing with a legacy system that has non-Rails conventional naming. Note that all tables and attributes are UPPERCASE, which in the sqlserver-adapter means that ID is NOT the same as id.
I had thought that alias_attribute :new, :OLD allowed you to specify a name that you could use in ActiveRecord/ActiveRelation queries. From what I'm seeing below (tested in rails console), that is not the case.
The end goal is making the legacy system "act" in a Rails-conventional methodology by making each model have an ID attribute, etc...
Model definition:
# app/models/organization.rb
class Organization < ActiveRecord::Base
self.table_name = "ORGANIZATION"
self.primary_key = "ORGANIZATION_ID"
alias_attribute :id, :ORGANIZATION_ID
end
Does not work:
Organization.select(:id) => invalid column name 'id'
Organization.select(:ID) => invalid column name 'ID'
Organization.select("ID") => invalid column name 'ID'
Does work:
Organization.select(:organization_id) => <finds record>
Organization.select(:ORGANIZATION_ID) => <finds record>
Organization.select("organization_id") => <finds record>
Organization.select("ORGANIZATION_ID") => <finds record>
I just used alias_attribute the other day. Honestly, I kept poking at it until I got mine to work.
I was able to achieve the functionality that you are looking for by reversing the params passed to alias_attribute.
Example:
alias_attribute :active?, :active
alias_attribute :alert, :message
alias_attribute :delete_at, :expire_at
Where the first param is what the column name is, and the second is what you are aliasing.
I understand that seems backwards from documentation, however this is how I got this to work.
I solved this situation by configuring the DB adapter (MS SQL Server) to treat the schema as all lowercase. Thus, even though the actual DB table names can be "USERS", "PEOPLE", etc..., I can reference them as "users", "people" in my application.
See: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter#force-schema-to-lowercase
Here's the code I added to resolve this:
# config/initializers/sql_server_adapter.rb
ActiveRecord::ConnectionAdapters::SQLServerAdapter.lowercase_schema_reflection = true
I'm unit-testing my Symfony 2 application with Codeception.
For one test, I want to fetch the associated entity in a one-to-one relationship, but I can't for the life of me figure out how to do it, because codeception complains no matter how I do it.
My first try:
$log_id = $I->grabFromRepository('BM2SiteBundle:Realm', 'log', array('id' => $realm_id));
error:
1) Failed to test the realm details in RealmBasicsCest::testRealmView
(/Volumes/User
Data/Users/Tom/Sites/BM2/src/BM2/SiteBundle/Tests/functional/RealmBasicsCest.php)
Sorry, I couldn't grab from repository
"BM2SiteBundle:Realm","log",{"id":1}:
Doctrine\ORM\Query\QueryException: [Semantical Error] line 0, col 9
near 'log FROM BM2\SiteBundle\Entity\Realm': Error: Invalid
PathExpression. Must be a StateFieldPathExpression.
2nd try:
$log_id = $I->grabFromRepository('BM2SiteBundle:EventLog', 'id', array('realm' => $realm_id));
error:
1) Failed to test the realm details in RealmBasicsCest::testRealmView
(/Volumes/User
Data/Users/Tom/Sites/BM2/src/BM2/SiteBundle/Tests/functional/RealmBasicsCest.php)
Sorry, I couldn't grab from repository
"BM2SiteBundle:EventLog","id",{"realm":1}:
Doctrine\ORM\Query\QueryException: A single-valued association path
expression to an inverse side is not supported in DQL queries. Use an
explicit join instead.
definition of the one-to-one relationship:
one-to-one field="log" target-entity="EventLog" inversed-by="realm" fetch="EXTRA_LAZY"
For further testing I need the id of the log to construct a URL.
On Magento 1.7 SOAP APIv2, i'm looking for a way to get a date range to retrieve information from the SOAP API.
$complexFilter = new filters();
$complexFilter->complex_filter = array(
array(
'key' => 'created_at',
'value' => array('key' => 'from', 'value' => '2012-12-17 00:00:00')
),
array(
'key' => 'created_at',
'value' => array('key' => 'to', 'value' => '2013-01-21 12:02:02')
),
);
This seemed like the most natural approach, but only the last criterion gets used. I also tried other combinations like a complex filter of complex filters, different ways to combine them, using gt and alike instead of from and co. Most of these approaches resulted in the same result: only the last criterion inside will be used.
What is the proper way to get a date range via the API? Can this also be done via a regular filter? If so, how to combine the start and end date?
I found a better way looking at the code in Magento!
Luckily it IS CASE SENSITIVE, so:
$complexFilter->complex_filter = array(
array(
'key' => 'CREATED_AT',
'value' => array('key' => 'from', 'value' => '2012-12-17 00:00:00')
),
array(
'key' => 'created_at',
'value' => array('key' => 'to', 'value' => '2013-01-21 12:02:02')
),
);
does the trick pretty neatly!
After googling a lot more i finally come to some explanation.
Obviously, the implementation of the complex filters does not allow more then one attribute to be present. This is also what I noticed during my tests: only the last attribute used influences the result. I therefore need to find another way of doing what I want. It's somehow sad to see that Magento does not provide an easy way to do this with ther SOAP API.
The final approach I used now is to determine a date that comes closest to what I want. Then just iterate through the results that that are in the daterange I want. This way (at least with our product data), I keep the load and results to a minumum and still get the desired products.
edit seems like the original link is down and the site doesn't exist anymore. The text above should be enough information. The blog merely showed some code examples with the faulty implementation.
Seems to be a bug in mage\sales\order\api\v2.php
Matlock provides a possible solution for this in the comment section of this thread: http://www.magentocommerce.com/bug-tracking/issue?issue=8073