BelongsTo not respecting empty and rules parameters #84

Open
rdlu opened this Issue Nov 3, 2010 · 2 comments

Comments

Projects
None yet
3 participants

rdlu commented Nov 3, 2010

In my model I have this BelongsTo field, that I want to be compulsory:

        'destination' => new Sprig_Field_BelongsTo(array(
                                                        'model'=>'Entity',
                                                        'column'=>'destination_id',
                                                        'empty' => false,
                                                        'rules'=>array('isId'=>array()))),

But my rule is not called, and I can select " -- None", even with explicit empty=false

I have checked the input() from Sprig_Field_BelongsTo class with FirePHP, in all belongsTo fields the empty becomes true. I tried to track where in the sprig code the options are being overwritten, but no luck...

Another issue is that I need to explicit the column option, since its trying to get the 'model_id' instead 'field_id' in database query (in my case entity_id instead of destination_id).

I'm using master branch HEAD here.

Thanks for your spent time ;)

Contributor

sfgeorge commented Nov 17, 2010

Thanks, will look into getting Foreign Keys to acknowledge properties like 'empty' and 'rules'.

As far as the column is concerned... I believe that this behavior is correct. Your child model being named Entity, Sprig's default behavior is to assume that a key named 'entity_id' would be placed on the parent model of the BelongsTo relationship.

However, you're right to mention it, as it can take a good bit of troubleshooting to realize the issu. Would like to get Sprig to better at throwing an Exception when the current column configuration is invalid and requires correction. Working on that on the strict branch d6a4964.

tadeck commented Jan 11, 2011

rodrigodk, when it comes to your first issue, you may want to use

'null' => false

instead of

'empty' => false

It will result in displaying no "-- None" option in select list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment