views:

159

answers:

3

Hi, I want to attribute some tags to some of the objects of my doctrine model.

I found sfDoctrineActAsTaggablePlugin which seems to be precisely what I need.

The problem is that when I want to save a Taggable object, I get this error:

Unknown record property / related component "saved_tags" on "Mishidea"

Mishidea is the name of the class/table that I want to be Taggable.

Here is the related portion of my schema.yml file:

Mishidea:
  connection: doctrine
  actAs: {Timestampable: ~ , Taggable: ~ }      
  tableName: mishidea
  columns:
    idea_id:
      type: integer(4)
      primary: true
      autoincrement: true
    idea_title:
      type: string()
      notnull: true
      primary: false
    idea_summary:
      type: string()
      notnull: true
      primary: false
    idea_description:
      type: string()
      notnull: true
      primary: false
    idea_up:
      type: integer(8)
      notnull: true
      default: 0
      primary: false
    idea_down:
      type: integer(8)
      notnull: true
      default: 0
      primary: false
    idea_confirmation:
      type: boolean(1)
      default: false
      primary: false
    group_id:
      type: integer(4)
      notnull: false
      primary: false
  relations:
    Mishgroup:
      local: group_id
      foreign: group_id
      type: one
    Ideacomment:
      local: idea_id
      foreign: idea_id
      type: many
    Mishdocument:
      local: idea_id
      foreign: idea_id
      type: many
    RelIdeafollower:
      local: idea_id
      foreign: idea_id
      type: many

I also tried other types of syntax for the actAs attribute of the class such as:

actAs:
    Timestampable: ~
    Taggable: ~

and:

actAs:[Timestampable,Taggable]

But it's not the problem as I get :

$timestampable0 = new Doctrine_Template_Timestampable();
$taggable0 = new Taggable();
$this->actAs($timestampable0);
$this->actAs($taggable0);

in the BaseMishidea.php class of my model.

I don't understand why the Mishidea class doesn't get the attributes that the Taggable class should add to it since the model seems to add the behaviour via the $this->actAs() statement.

How to get this plugin working?

If that helps, I use Symfony 1.4 with MySQL/InnoDB and I had tried before with the PostgreSql DBMS, with the same result.

Your help would be much appreciated.

Thanks

FuzzyTern


EDIT1 - Regarding what said johnwards : Can anyone confirm that the Taggable behaviour is added in the schema.yml file via "actAs:", not "templates:"? That's what I read here and there (see my comment on johnwards' post) but since neither of both solutions work for me, I'm not sure. When using the "templates" keyword I get:

Unknown method Mishidea::addTag

and the specific classes of the model aren't generated.


EDIT2 - After a further investigation, I found that the Symfony stack trace is interresting. Indeed, when I do:

$idea = new Mishidea();
$idea->save();

the TaggableListener is called (point 8 in the stack trace below), which shows that the relation is working. But then I don't understand what's going on and leads to the exception.

Stack trace:

1. at ()
in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record/Filter/Standard.php line 55 ...

    public function filterGet(Doctrine_Record $record, $name)

    {

        throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $name, get_class($record)));

    }

}

2. at Doctrine_Record_Filter_Standard->filterGet(object('Mishidea'), 'saved_tags')
in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php line 1374 ...
3. at Doctrine_Record->_get('saved_tags', 1)
in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php line 1333 ...
4. at Doctrine_Record->get('saved_tags')
in n/a line n/a ...
5. at call_user_func_array(array(object('Mishidea'), 'get'), array('saved_tags'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/record/sfDoctrineRecord.class.php line 212 ...
6. at sfDoctrineRecord->__call('getSavedTags', array())
in n/a line n/a ...
7. at Mishidea->getSavedTags()
in SF_ROOT_DIR/plugins/sfDoctrineActAsTaggablePlugin/lib/TaggableTemplate.class.php line 93 ...
8. at TaggableListener->postSave(object('Doctrine_Event'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record/Listener/Chain.php line 237 ...
9. at Doctrine_Record_Listener_Chain->postSave(object('Doctrine_Event'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php line 355 ...
10. at Doctrine_Record->invokeSaveHooks('post', 'save', object('Doctrine_Event'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/UnitOfWork.php line 112 ...
11. at Doctrine_Connection_UnitOfWork->saveGraph(object('Mishidea'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php line 1691 ...
12. at Doctrine_Record->save()
in SF_ROOT_DIR/apps/frontend/modules/idea/actions/actions.class.php line 24 ...

If someone wants to see the code for any point of the stack trace (only 1. is expanded here), just ask. Any suggestion is welcomed.

A: 

Edit: Have you done a build all reload?

You need to add templates: [Taggable] to your schema not actAs.

Mishidea:
  connection: doctrine
  actAs: [Timestampable]    
  templates: [Taggable]  
  tableName: mishidea
  columns:
    idea_id:
      type: integer(4)
      primary: true
      autoincrement: true
johnwards
Thanks johnward, but are you sure?It's what is indeed written on the official documentation (see link in my first post), but some sources say that the documentation is erroneous and that we should use "actAs", not "templates". (http://n8v.enteuxis.org/2010/05/adding-wordpress-like-tags-to-a-symfony-1-4-admin-generator-form/ , http://www.mail-archive.com/[email protected]/msg26173.html)If I follow your advice, the doctrine:build --all works fine (just as before) but when I use one of the Taggable function I get:Unknown method Mishidea::addTagAny idea?
FuzzyTern
I was just basing the answer from the docs. Have you searched your code for saved_tags to see where that is getting called?
johnwards
saved_tags is only present in the TaggableTemplate.class.php which is part of the plugin. I just edited my original post to add a portion of the stack trace I get. It proves that the relation is working but I don't understand what's wrong in the end. If this stack trace inspires you, feel free to share your inspiration :-)
FuzzyTern
I bet you have but just checking, you've done a build all reload?
johnwards
Yes I did, and it indeed seems to me that the model doesn't match my database for some reason... It seems weird though because I tried the operation dozens of times with two different DBMS (postgres and mysql), and also doing a "symfony doctrine:build --all --and-load" each time... :-/
FuzzyTern
A: 

Possible Issues:

Make sure you have the plugin enabled

In ProjectConfiguration::setup, you should have

$this->enablePlugins(array(
  'sfDoctrineActAsCommentablePlugin', //plus other plugins, like Doctrine
));

Set Up Your Schema Correctly

It should look like this:

ModelClass:
  actAs:
    Taggable:
  columns: //etc

You should be using actAs not templates.

I don't believe you need to set an explicit relations for Tags, but I could be wrong about that. If you let me know, I will edit this answer.

jeremy
+1  A: 

Whoop whoop!! I solved this problem, at last!

Well... The problem is that the sfDoctrineActAsTaggablePlugin plugin does work only for taggable objects which have an id property called precisely "id". I like to put the name of the entity in the name of my properties, that's why I called the idea of my taggable entity "idea_id".

As soon as I replaced "idea_id" by "id" everything worked like a charm (you may have several changes to do in the schema.yml and maybe even in the routing.yml file later on).

I don't know if I'm clear enough so don't hesitate to ask me further explanations.

Anyway that's a bit of a shame for this plugin, it is not generic enough (will report this to the developers).

BTW, all the syntaxes for actAs written in my first post are equivalent, use whichever you prefer.

Thank you all for your help, each reply was an encouragement without which I wouldn't have had the strength to find the bug ;).

Cheers

FuzzyTern