Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8404347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:34:36+00:00 2026-06-09T22:34:36+00:00

I have a model that extends CActiveRecord that has the following rules() method: /**

  • 0

I have a model that extends CActiveRecord that has the following rules() method:

/**
 * @return array validation rules for model attributes.
 */
public function rules()
{
    return array(
        array('name, locationId', 'required'),
        array('locationId', 'numerical', 'integerOnly'=>true),
        array('name', 'length', 'max'=>1024),
        array('name', 'safe'),
        // The following rule is used by search().
        // Please remove those attributes that should not be searched.
        array('id, name, description, locationId', 'safe', 'on'=>'search'),
    );
}

Here’s the actionCreate() method in the respective controller:

public function actionCreate()
{
    $model = new Destination;

    if ( isset($_POST['Destination']) )
    {
      $model->attributes = $_POST['Destination'];

      // logging statement!
      Yii::log("Name: {$model->name}\nLocationID: {$model->locationId}\nAll attribs:\n".CVarDumper::dumpAsString($model->attributes), 'warning', 'application.controllers.DestinationController.actionCreate');

      if ( $model->save() )
        $this->redirect(array('view', 'id'=>$model->id));
    }

    $this->render( 'create', array (
        'model' => $model,
    ));
}

Unfortunately, very time I try to create a new record with this action, I get errors that name and locationId cannot be empty, even though they’ve been set in the form. Output from the logging statement in actionCreate(), above, looks like this:

2012/08/14 18:04:51 [warning]     [application.controllers.DestinationController.actionCreate] Name:
LocationID:
All attribs:
array
(
    'name' => 'Test Name'
    'description' => 'Test Description'
    'locationId' => '93'
    'contactId' => ''
    'accessId' => ''
    'fullDistance' => ''
)

As you can see, dumping $model->attributes shows correct data, but trying to get individual attribues (e.g. calling $model->name or $model->locationId) returns nothing. I traced this through the save(), validate(), etc. calls, and it looks like this is causing the required rule for name and locationId to fail.

Any ideas?

EDIT: Additional log info

    2012/08/15 16:58:03 [info] [application] Model:
Destination#1
(
    [CActiveRecord:_md] => CActiveRecordMetaData#2
    (
        [tableSchema] => CMysqlTableSchema#3
        (
            [schemaName] => null
            [name] => 'destination'
            [rawName] => '`destination`'
            [primaryKey] => 'id'
            [sequenceName] => ''
            [foreignKeys] => array
            (
                'accessId' => array
                (
                    '0' => 'access'
                    '1' => 'id'
                )
                'contactId' => array
                (
                    '0' => 'contact'
                    '1' => 'id'
                )
                'locationId' => array
                (
                    '0' => 'location'
                    '1' => 'id'
                )
            )
            [columns] => array
            (
                'id' => CMysqlColumnSchema#4
                (
                    [name] => 'id'
                    [rawName] => '`id`'
                    [allowNull] => false
                    [dbType] => 'int(11)'
                    [type] => 'integer'
                    [defaultValue] => null
                    [size] => 11
                    [precision] => 11
                    [scale] => null
                    [isPrimaryKey] => true
                    [isForeignKey] => false
                    [autoIncrement] => true
                    [CComponent:_e] => null
                    [CComponent:_m] => null
                )
                'name' => CMysqlColumnSchema#5
                (
                    [name] => 'name'
                    [rawName] => '`name`'
                    [allowNull] => false
                    [dbType] => 'varchar(1024)'
                    [type] => 'string'
                    [defaultValue] => null
                    [size] => 1024
                    [precision] => 1024
                    [scale] => null
                    [isPrimaryKey] => false
                    [isForeignKey] => false
                    [autoIncrement] => false
                    [CComponent:_e] => null
                    [CComponent:_m] => null
                )
                'description' => CMysqlColumnSchema#6
                (
                    [name] => 'description'
                    [rawName] => '`description`'
                    [allowNull] => true
                    [dbType] => 'text'
                    [type] => 'string'
                    [defaultValue] => null
                    [size] => null
                    [precision] => null
                    [scale] => null
                    [isPrimaryKey] => false
                    [isForeignKey] => false
                    [autoIncrement] => false
                    [CComponent:_e] => null
                    [CComponent:_m] => null
                )
                'locationId' => CMysqlColumnSchema#7
                (
                    [name] => 'locationId'
                    [rawName] => '`locationId`'
                    [allowNull] => false
                    [dbType] => 'int(11)'
                    [type] => 'integer'
                    [defaultValue] => null
                    [size] => 11
                    [precision] => 11
                    [scale] => null
                    [isPrimaryKey] => false
                    [isForeignKey] => true
                    [autoIncrement] => false
                    [CComponent:_e] => null
                    [CComponent:_m] => null
                )
                'contactId' => CMysqlColumnSchema#8
                (
                    [name] => 'contactId'
                    [rawName] => '`contactId`'
                    [allowNull] => true
                    [dbType] => 'int(11)'
                    [type] => 'integer'
                    [defaultValue] => null
                    [size] => 11
                    [precision] => 11
                    [scale] => null
                    [isPrimaryKey] => false
                    [isForeignKey] => true
                    [autoIncrement] => false
                    [CComponent:_e] => null
                    [CComponent:_m] => null
                )
                'accessId' => CMysqlColumnSchema#9
                (
                    [name] => 'accessId'
                    [rawName] => '`accessId`'
                    [allowNull] => true
                    [dbType] => 'int(11)'
                    [type] => 'integer'
                    [defaultValue] => null
                    [size] => 11
                    [precision] => 11
                    [scale] => null
                    [isPrimaryKey] => false
                    [isForeignKey] => true
                    [autoIncrement] => false
                    [CComponent:_e] => null
                    [CComponent:_m] => null
                )
                'fullDistance' => CMysqlColumnSchema#10
                (
                    [name] => 'fullDistance'
                    [rawName] => '`fullDistance`'
                    [allowNull] => true
                    [dbType] => 'int(11)'
                    [type] => 'integer'
                    [defaultValue] => null
                    [size] => 11
                    [precision] => 11
                    [scale] => null
                    [isPrimaryKey] => false
                    [isForeignKey] => false
                    [autoIncrement] => false
                    [CComponent:_e] => null
                    [CComponent:_m] => null
                )
            )
            [CComponent:_e] => null
            [CComponent:_m] => null
        )
        [columns] => array
        (
            'id' => CMysqlColumnSchema#4(...)
            'name' => CMysqlColumnSchema#5(...)
            'description' => CMysqlColumnSchema#6(...)
            'locationId' => CMysqlColumnSchema#7(...)
            'contactId' => CMysqlColumnSchema#8(...)
            'accessId' => CMysqlColumnSchema#9(...)
            'fullDistance' => CMysqlColumnSchema#10(...)
        )
        [relations] => array
        (
            'location' => CBelongsToRelation#11
            (
                [joinType] => 'LEFT OUTER JOIN'
                [on] => ''
                [alias] => null
                [with] => array()
                [together] => null
                [scopes] => null
                [name] => 'location'
                [className] => 'Location'
                [foreignKey] => 'locationId'
                [select] => '*'
                [condition] => ''
                [params] => array()
                [group] => ''
                [join] => ''
                [having] => ''
                [order] => ''
                [CComponent:_e] => null
                [CComponent:_m] => null
            )
            'activities' => CManyManyRelation#12
            (
                [limit] => -1
                [offset] => -1
                [index] => null
                [through] => null
                [joinType] => 'LEFT OUTER JOIN'
                [on] => ''
                [alias] => null
                [with] => array()
                [together] => null
                [scopes] => null
                [name] => 'activities'
                [className] => 'Activity'
                [foreignKey] => 'destinationHasActivity(destinationId, activityId)'
                [select] => '*'
                [condition] => ''
                [params] => array()
                [group] => ''
                [join] => ''
                [having] => ''
                [order] => ''
                [CComponent:_e] => null
                [CComponent:_m] => null
            )
            'attributes' => CManyManyRelation#13
            (
                [limit] => -1
                [offset] => -1
                [index] => null
                [through] => null
                [joinType] => 'LEFT OUTER JOIN'
                [on] => ''
                [alias] => null
                [with] => array()
                [together] => null
                [scopes] => null
                [name] => 'attributes'
                [className] => 'Attribute'
                [foreignKey] => 'destinationHasAttribute(destinationId, attributeId)'
                [select] => '*'
                [condition] => ''
                [params] => array()
                [group] => ''
                [join] => ''
                [having] => ''
                [order] => ''
                [CComponent:_e] => null
                [CComponent:_m] => null
            )
            'surfaces' => CManyManyRelation#14
            (
                [limit] => -1
                [offset] => -1
                [index] => null
                [through] => null
                [joinType] => 'LEFT OUTER JOIN'
                [on] => ''
                [alias] => null
                [with] => array()
                [together] => null
                [scopes] => null
                [name] => 'surfaces'
                [className] => 'Surface'
                [foreignKey] => 'destinationHasSurface(destinationId, surfaceId)'
                [select] => '*'
                [condition] => ''
                [params] => array()
                [group] => ''
                [join] => ''
                [having] => ''
                [order] => ''
                [CComponent:_e] => null
                [CComponent:_m] => null
            )
            'images' => CManyManyRelation#15
            (
                [limit] => -1
                [offset] => -1
                [index] => null
                [through] => null
                [joinType] => 'LEFT OUTER JOIN'
                [on] => ''
                [alias] => null
                [with] => array()
                [together] => null
                [scopes] => null
                [name] => 'images'
                [className] => 'Image'
                [foreignKey] => 'destinationHasImage(destinationId, imageId)'
                [select] => '*'
                [condition] => ''
                [params] => array()
                [group] => ''
                [join] => ''
                [having] => ''
                [order] => ''
                [CComponent:_e] => null
                [CComponent:_m] => null
            )
        )
        [attributeDefaults] => array()
        [CActiveRecordMetaData:_model] => Destination#16
        (
            [CActiveRecord:_md] => CActiveRecordMetaData#2(...)
            [CActiveRecord:_new] => false
            [CActiveRecord:_attributes] => array()
            [CActiveRecord:_related] => array()
            [CActiveRecord:_c] => null
            [CActiveRecord:_pk] => null
            [CActiveRecord:_alias] => 't'
            [CModel:_errors] => array()
            [CModel:_validators] => null
            [CModel:_scenario] => ''
            [CComponent:_e] => null
            [CComponent:_m] => null
        )
    )
    [CActiveRecord:_new] => true
    [CActiveRecord:_attributes] => array()
    [CActiveRecord:_related] => array
    (
        'attributes' => array
        (
            'name' => 'Test name'
            'description' => ''
            'contactId' => ''
            'fullDistance' => ''
        )
    )
    [CActiveRecord:_c] => null
    [CActiveRecord:_pk] => null
    [CActiveRecord:_alias] => 't'
    [CModel:_errors] => array()
    [CModel:_validators] => null
    [CModel:_scenario] => 'insert'
    [CComponent:_e] => null
    [CComponent:_m] => null
)

Safe Attributes:

2012/08/15 16:58:03 [info] [application] Safe attributes:
array
(
    '0' => 'name'
    '1' => 'locationId'
    '2' => 'fullDistance'
    '3' => 'description'
)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:34:38+00:00Added an answer on June 9, 2026 at 10:34 pm

    It was a naming collision. There is an ‘attribute’ table in this db, and a relation $model->attributes that references that table. The Yii-generated code does massive assignment on this line:

    $model->attributes = $_POST['Destination'];
    

    and since $model->attributes has been redefined as a relation, the massive assignment doesn’t take correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Model that named word. this is my word model public class
I have a model that looks like: [Serializable] public class TemplatePageModel { public PageModel
I have a model that has a ForeignKey to the built-in user model in
I have a model that uses a acts_as_nested_set fork, and I've added a method
I have one model that has a $hasMany attribute. If I just have the
I want to have a general product model that has basic info like name,
I have some classes extended this way: class Baseresidence extends CActiveRecord { public static
I have a model that looks like this: @MappedSuperclass @AccessType(field) public abstract class BaseEntity
basically I am trying to model some map brushes that have the following format:
Following situation: At work we have an own plugin that extends some JDT features

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.