Hello,

What would be the best practice to access extra fields in refClass.

I have following many to many schema:

Item:
  actAs: { Timestampable: ~ }
  columns:
    name:
      type: string(255)
      notnull: true
    file:
      type: string(255)
      notnull: true

Collection:
  actAs: { Timestampable ~ }
  columns:
    name:
      type: string(255)
      notnull: true
  relations:
    Items:
      class: Item
      refClass: ItemCollection
      local: collection_id
      foreign: item_id


ItemCollection:
  actAs: { Timestampable: ~ }
  columns:
    item_id:
      type: integer(8)
      primary: true
    collection_id:
      type: integer(8)
      primary: true
    weight:
      type: integer(8)
  relations:
    Item:
      local: item_id
      foreign: id
    Collection:
      local: collection_id
      foreign: id


In order to get collection sorted by weight and display weight of
every item in collection I tried following query

$items = Doctrine_Query::create()
                ->select('*')
                ->from('Item i')
                ->innerJoin('i.ItemCollection ic')
                ->addWhere('ic.collection_id='.$collection_id)
                ->orderBy('ic.weight DESC')
                ->execute();


And to get the item I tried following
$items[0]->getName();
$items[0]->getMediaCollection()->getWeight();

But this throws error on getWeight() line
Fatal error: Call to undefined method Doctrine_Collection::getWeight()

so my next try was (after inspecting the returned collection)

$items[0]->ItemCollection[0]->getWeight();

This did worked but I am not sure this is the right way to do it.

using symfony 1.8

Keep up the good work on this excellent framework.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to