Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in MongoDB types #31

Closed
salehsed opened this issue Oct 18, 2011 · 27 comments
Closed

Error in MongoDB types #31

salehsed opened this issue Oct 18, 2011 · 27 comments

Comments

@salehsed
Copy link

I'm trying to create an admin for The User document in FosUserBundle. That document has a "role" attribute that the type is "hash"
And when the admin controller tries to show the page , it'll throw

An exception has been thrown during the rendering of a template ("The dbType "hash" is not yet implemented") in "ListBuilderAction.php.twig" at line 73. 
@cedriclombardot
Copy link
Member

hash is not a dbtype !! That means the field guesser have not find the model type. see : https://github.com/cedriclombardot/AdmingeneratorGeneratorBundle/blob/master/Guesser/DoctrineODMFieldGuesser.php

It's normally take the dbType from doctrine mapping. If it's doesn't work, you could add in your yaml :

fields:
   hashField:
      dbType: string

@cedriclombardot
Copy link
Member

In fact hash seems really be a type ! https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/config/doctrine/User.mongodb.xml

Could you try to complete the guesser ?? probably with a "collection" dbType ??

@salehsed
Copy link
Author

@salehsed
Copy link
Author

I'll work on it

@cedriclombardot
Copy link
Member

Thx for to link, i ll try to implement all fields.

Could you do it for hash ? My mongo db env is down tonight i've a fatal doctrine/mongodb-odm#175

@salehsed
Copy link
Author

Now I'm not sure how to do that .
@cedriclombardot: did you find any chance to do it ?

@cedriclombardot
Copy link
Member

For me there is only to update https://github.com/cedriclombardot/AdmingeneratorGeneratorBundle/blob/master/Guesser/DoctrineODMFieldGuesser.php switchs to add the hash case hash in getFormType et getFilterType

@salehsed
Copy link
Author

salehsed commented Nov 9, 2011

Is it possible for you to add the "hash" forms and the gusser + filters

@cedriclombardot
Copy link
Member

i ll work on it this week

@salehsed
Copy link
Author

salehsed commented Nov 9, 2011

Thanks , you're a life saver

cedriclombardot added a commit that referenced this issue Nov 11, 2011
cedriclombardot added a commit that referenced this issue Nov 11, 2011
@cedriclombardot
Copy link
Member

@salehsed it's ok for hash i'll will look for other fields

@salehsed
Copy link
Author

@cedriclombardot that's awesome.
please also check the "Add" button under hash type (on the form), because it's not working

@cedriclombardot
Copy link
Member

It's works for me ! Have you got a js error ?? Have you publish assets before ? Do you use a specific theme ActiveAdmin or original or your own ??

@salehsed
Copy link
Author

We used custom template and extend the blocks
in app/Resources/views/base_admin_assetic_less.html.twig

{% extends "::base.html.twig" %}

{% block main %}


<div id="content">
    {% block flashes %}
                {% if app.session.flash('success') %}
    <div class="notification_box success">
                        {{ app.session.flash('success') }}
        </div>
                {% endif %}
                {% if app.session.flash('error') %}
        <div class="notification_box error">
                        {{ app.session.flash('error') }}
        </div>
                {% endif %}
            {% endblock %}

            {% block body %}{% endblock %}
        </div>
{% endblock %}

        {% block stylesheets %}
            <link rel="stylesheet" href="{{ asset('/bundles/admingeneratorgenerator/css/all.css') }}" type="text/css" media="all" />
            <!--[if IE]>
                <link href="{{ asset('/bundles/admingeneratorgenerator/css/ie.css') }}" rel="stylesheet" type="text/css" />
            <![endif]-->
        {% endblock %}

@cedriclombardot
Copy link
Member

Ok so you have to add a jquery because the add code is :

    $(document).ready(function() {

                type_collection_hashField_nextId = $('#edit_movie_hashField > div').length;

        $('#type_collection_hashField .new').click(function() {
           var prototype = $('#edit_movie_hashField').attr('data-prototype');
           prototype = prototype.replace(/\$\$name\$\$/g, type_collection_hashField_nextId);
           type_collection_hashField_nextId++;
           $('#edit_movie_hashField').append(prototype);

                      $('#edit_movie_hashField > div:last').append("<a class=\"delete\"> </a>");

           $('#edit_movie_hashField .delete').click(function() { //@todo make a function for this
               $(this).parent('div').remove();
            });
                   });

                    $('#edit_movie_hashField > div').append("<a class=\"delete\"> </a>");

            $('#edit_movie_hashField .delete').click(function() {
               $(this).parent('div').remove();
            });

@salehsed
Copy link
Author

is there any way to make the js more general , because it seems to just work with "MOVIE" scenario
because the selectors are using

$('#edit_movie_hashField > div')

@cedriclombardot
Copy link
Member

The js is auto generated ;) so it correspond automatically with you field look into your source you will see thats correspond to your field name https://github.com/cedriclombardot/AdmingeneratorGeneratorBundle/blob/master/Resources/templates/CommonAdmin/EditTemplate/Type/collection.php.twig

@salehsed
Copy link
Author

can you tell me which twig block is getting the js codes ?

@cedriclombardot
Copy link
Member

I m not sure to understand about wich block you speack,

The field block is form_{youtFieldName} open the file in your app/cache/dev/Admingenerated/.... to see
The main js eg jquery is loaded in the theme https://github.com/cedriclombardot/AdmingeneratorGeneratorBundle/blob/master/Resources/views/base_admin_assetic_less.html.twig block javascripts

@madarco
Copy link

madarco commented Jan 25, 2012

I have a similar problem, but with the Collection field type:

/** @MongoDB\Collection */
private $serviceTypes = array();

I get this error:

An exception has been thrown during the rendering of a template ("Notice: Undefined index: targetDocument in /mnt/www/commercialista/symfony/vendor/bundles/Admingenerator/GeneratorBundle/Guesser/DoctrineODMFieldGuesser.php line 167") in ListBuilderAction.php.twig at line 125.

I am missing something?

@cedriclombardot
Copy link
Member

Is it possible to have a Collection without targetDocument parameter in doctrine ? I tink your line should like

    /**
     * @MongoDB\Colelction(targetDocument="Admingenerator\DoctrineODMDemoBundle\Document\Producer")
     */

@madarco
Copy link

madarco commented Jan 30, 2012

Yes, it maps to an array of strings. (eg: a list of tags)

It is especially useful with MongoDb for his support of "Multikeys": http://www.mongodb.org/display/DOCS/Multikeys

@cedriclombardot
Copy link
Member

Finally what is the difference with hash ?

is "Multikeys" collection :

{ 
name: "Warm Weather",
author: "Steve", 
tags: ['weather', 'hot', 'record', 'april']
} 

isn't an object with a field name, author and an hash tags ? in an odm ?

@madarco
Copy link

madarco commented Jan 31, 2012

The type "Collection" is like the Hash but with numeric indexes.

In your example the document class would be:

class Book {
  /** @MongoDB\String */
  private $name;

  /** @MongoDB\String */
  private $name;

  /** @MongoDB\Collection */
  private $tags = array();
}

Also notice that the Collection doesn't have the targetDocument attribute (Unlike ReferenceMany: http://www.doctrine-project.org/docs/mongodb_odm/1.0/en/reference/reference-mapping.html)

@cedriclombardot
Copy link
Member

@madarco
Copy link

madarco commented Jan 31, 2012

If it can help, I've (partially) fixed the issue with:

fields:
  services:
    dbType: hash
    formType: choice

However in the List its displayed only "Array" in the services column and the update doesn't work.

@neoshadybeat
Copy link
Contributor

issue closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants