Skip to content

fix . notation support for odm - #674

Closed
mamamiapeguin wants to merge 0 commit into
APY:masterfrom
mamamiapeguin:master
Closed

mamamiapeguin wants to merge 0 commit into
APY:masterfrom
mamamiapeguin:master

Conversation

@mamamiapeguin

Copy link
Copy Markdown
Contributor

Actually '.' notation works well when executing the query. The following filling record into row caused the data missing.
So I added the logic to handle '.' notation at APY\DataGridBundle\Grid\Source\Document::execute() line 205

foreach ($columns as $column) {
      $hierarchy = explode('.', $column->getId());
      $length = count($hierarchy);
      $node = $resource;
      for ($i = 0; $i < $length; $i++) {
            if (isset($node)) {
                 $node = $this->getClassProperties($node);
                 $node = $node[strtolower($hierarchy[$i])];
            }
      }
      $row->setField($column->getId(), $node);
}

In case of annotation field differs in uppercase/lowercase from actual class property , I had them unified in lowercase:

$result[strtolower($property->getName())] = $property->getValue($obj);

To access referenced document's property, the referenced document's id is a must whatever actual property is eventually retrieved.
At class annotation:

@GRID\Source(columns = "id, owner.id, owner.username")

At property 'owner' annotation:

@GRID\Column(field = "owner.id", visible = false)
@GRID\Column(field = "owner.username")

@tomcyr

tomcyr commented Jan 10, 2015

Copy link
Copy Markdown
Contributor

+1 This works for me but only for embed documents.
But for referenced I have error: Notice: Undefined index: $id

@mamamiapeguin

Copy link
Copy Markdown
Contributor Author

@tomcyr , you have to add referenced document's id in the annotation to make it work. Example is at the end of my previous comment.

@tomcyr

tomcyr commented Jan 11, 2015

Copy link
Copy Markdown
Contributor

@mamamiapeguin I tried as You write, but now I have following error:
localhost:27017: Positional operator does not match the query specifier.
in vendor/doctrine/mongodb/lib/Doctrine/MongoDB/Cursor.php at line 483
my annotations:

/**
 * @GRID\Source(columns="id, name, description, file, threatGroup.id, threatGroup.name, created,  updated")
 */
class Threat
.
.
.
/**
     * @MongoDB\ReferenceOne(targetDocument="ThreatGroup")
     * @GRID\Column(field="threatGroup.id", visible=false)
     * @GRID\Column(field="threatGroup.name", title="Threat Group")
     */
    private $threatGroup;

@mamamiapeguin

Copy link
Copy Markdown
Contributor Author

Sorry, @tomcyr . I cannot recur your error. However, I noticed that you didn't have @mongodb annotation for the class. Maybe this is the problem.

@tomcyr

tomcyr commented Jan 12, 2015

Copy link
Copy Markdown
Contributor

@mamamiapeguin I have @mongodb annotation for class (but I not copied here). However I'm preparing fix for referenced columns in Document, so when I'll finish (I must refactor some code) I share this code here so You'll be able to see where's the problem :)

@tomcyr

tomcyr commented Jan 12, 2015

Copy link
Copy Markdown
Contributor

@mamamiapeguin please look at this commit tomcyr@32ee860 This works for me for @mongodb\ReferenceOne mappings (without sorting).
And in Document notation must be:

/**
 * @MongoDB\Document
 * @GRID\Source(columns="id, referenceColumn, referenceColumn.name")
 */
class DocumentExample
.
.
.
/**
  * @MongoDB\ReferenceOne(targetDocument="referenceDocument")
  * @GRID\Column(field="referenceColumn", visible=false)
  * @GRID\Column(field="referenceColumn.name")
  */
    private $referenceColumn;

There isn't other way to find Documents in MongoDB by referenced columns in other Document.

@hmert hmert modified the milestone: 2.3 Dec 13, 2015
@hmert

hmert commented Dec 13, 2015

Copy link
Copy Markdown
Contributor

@mamamiapeguin ping! could you test if this is working now. Tests are passed but I'd like to hear from you.

@hmert

hmert commented Dec 13, 2015

Copy link
Copy Markdown
Contributor

#32

@mamamiapeguin

Copy link
Copy Markdown
Contributor Author

@hmert checked. It works well.

@hmert

hmert commented Jan 12, 2016

Copy link
Copy Markdown
Contributor

@mamamiapeguin Hey, it has a conflict right now.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants