Hi again,
It seems to be some issue with the form
I set up the element as follows:
class BuildingForm extends Form
{
public function __construct(EntityManager $em)
{
... lots of fields ..
$this->add(array(
'name' => 'building_ownership',
'type' =>
'DoctrineModule\Form\Element\ObjectSelect',
'options' => array(
'label' =>
'Ownership',
'object_manager' => $em,
'target_class' =>
'Assets\Model\BuildingOwnership',
'property' =>
'asset_owner',
'empty_option' =>
'Choose..',
'allow_empty' => true,
'required' => false,
'nullable' => true,
),
)
);
... more fields.
}
In the controller I do the following:
$form = new BuildingForm ($this->getEntityManager ());
$form->setBindOnValidate ( false );
$form->bind ( $building );
$elements = $form->getElements();
$bown = $elements['building_ownership'];
echo __FILE__." : ".__LINE__." What we got Building Ownership Vars -
options <pre>";
var_dump(($bown->getInputSpecification()));
//var_dump($bown->getOptions());
die("</pre>");
And get:
array(3) {
["name"]=>
string(18) "building_ownership"
["required"]=>
bool(true)
["validators"]=>
array(1) {
[0]=>
-- lots more
What I cant understand is why I get
["required"]=> bool(true)
When I try hard to set it to false.
I am completely stuck at persent because this pattern is spread right
across my application.
Barry
On Tuesday, 29 April 2014 12:45:08 UTC+10, Barry Steele wrote:
>
> Hi,
> Thanks Jason.
>
> I'll try that.
>
> Stay well,
> Barry
>
>
> On Monday, 28 April 2014 16:48:59 UTC+10, Jàπ (Jasper N. Brouwer) wrote:
>>
>> Hi Barry,
>>
>> You can specify if the foreign key used in an association should be
>> nullable or not:
>>
>> /**
>> * @ManyToOne(targetEntity="SportingTeam")
>> * @JoinColumn(name="team_id", referencedColumnName="id",
>> nullable=TRUE)
>> */
>> private $sportingTeam;
>>
>> I'm not sure about the form, this is not something of Doctrine.
>>
>> PS: Doctrine itself doens't enforce properties to be "not null", but when
>> the database is in sync with your mapping data, and you have a NOT NULL
>> property, the database ofcourse will enforce this :)
>>
>> --
>> Jasper N. Brouwer
>> (@jaspernbrouwer)
>>
>>
>> On 28 April 2014 at 06:23:56, Barry Steele ([email protected]) wrote:
>> > I have an applciation with a large number of tables, which is no real
>> issue.
>> >
>> > I do however have the following problem:
>> >
>> > Example
>> >
>> >
>> > InterestingPeople
>> >
>> > id : identifier
>> > sporting_team: team_id Null, (Nb Null values are perfectly reasonable =
>> > might have no sporting affiliations)
>> >
>> > ... other columns.
>> >
>> >
>> > sporting_team:
>> >
>> > id: identifier
>> > name
>> >
>> > Note. that the entries in the People table may have a sporting team, or
>> not.
>> >
>> > But if they do have a sporting team it must be in the Sporting Team
>> table.
>> >
>> > This is a perfectly reasonable RDBMS schema and is handled very nicely
>> in
>> > SQL, etc.
>> >
>> > I have tried to use "'DoctrineModule\Form\Element\ObjectSelect:" id
>> build
>> > a drop down select, which works as expected.
>> >
>> > But the Form will not validate as for some reason the form will not
>> accept
>> > a null in that field.
>> >
>> > I've seen a few posts about this but I would like to understand why
>> this
>> > behaviour exists before committing any great effort to building the
>> rest of
>> > the DBAL .
>> >
>> > Does Doctrine try to enforce "NOT NULL" in this situation?
>> >
>> > If so, is there any reason? How do I overwrite it?
>> >
>> > Stay well,
>> > Barry
>>
>>
>>
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.