cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

Can't save relation in model if alias is camelCase

Open nsossonko opened this issue 11 years ago • 8 comments

Model Foo has a bidirectional belongsTo/hasMany relationship with model BarBaz. In the relationship on Foo we aliased BarBaz as barBaz. If we try to save the model as follows:

$foo = new Foo();
$barBaz = new BarBaz();
$foo->barBaz = $barBaz;
$foo->create();

It screws up $foo (getMessages returns null [not even empty array, null] and the create call returns null). The creation also does not work. However, if the following is done:

$foo = new Foo();
$barBaz = new BarBaz();
$foo->barbaz = $barBaz;
$foo->create();

It will work properly. $foo->barBaz will be empty but $foo->barbaz will contain the nested relation and both will have been created.

nsossonko avatar Sep 03 '15 20:09 nsossonko

Are you printing if any message is being created after save the record?

print_r($foo->getMessages());

andresgutierrez avatar Sep 03 '15 21:09 andresgutierrez

As I mentioned initially, getMessages returns null (not even empty array) on $foo.

nsossonko avatar Sep 03 '15 21:09 nsossonko

@andresgutierrez Is this case somehow related to #10800 and #10779?

Both of them are issues related to lowercase and camelCase alias.

tobasar avatar Sep 07 '15 14:09 tobasar

@tobasar Thanks for pointing it out, taking a look

andresgutierrez avatar Sep 07 '15 14:09 andresgutierrez

@andresgutierrez Any progress about this bug? Would love to help testing this bug again if you need.

tobasar avatar Sep 27 '15 15:09 tobasar

@andresgutierrez I saw in manager.zep line 1100

/**
     * Returns a relation by its alias
     */
    public function getRelationByAlias(string! modelName, string! alias) -> <Relation> | boolean
    {
        var aliases, relation;
        let aliases = this->_aliases;
        if typeof aliases == "array" {
            if fetch relation, aliases[strtolower(modelName . "$" . alias)] {
                return relation;
            }
        }
        return false;
    }

What is the point lowering case the alias? Could it be the hiccup?

tobasar avatar Oct 13 '15 14:10 tobasar

@nsossonko any update about this bug?

tobasar avatar Nov 21 '15 13:11 tobasar

@tobasar I don't see this issue anymore in my application. Not sure why...

nsossonko avatar May 06 '16 13:05 nsossonko