Doctrine Project

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What’s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
Doctrine MongoDB ODM
  • Doctrine MongoDB ODM
  • MODM-64

@DynamicFields

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: New Feature New Feature
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Invalid
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

I suggest adding a new feature called @DynamicFields. The idea is from roman and documeneted here: http://github.com/romanb/couchdb-persistence-api/blob/master/src/main/java/org/code_factory/couch/annotations/DynamicFields.java

Idea: Save all "left-over" fields of the result in an array.

This would greatly enhance the flexibility of document mappers

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • History
  • Activity
  • Source
Hide
Permalink
Jonathan H. Wage added a comment - 28/Aug/10 11:25 AM

Nice idea! So something like this could essentially work:

/** @Document */
class User
{
    /** @DynamicFields */
    public $data;
}

$user = $dm->find(....);
echo $user->data['username'];

I am not sure if it is a good idea to just allow them to use a single @DynamicFields, maybe we should throw an exception if they use it that way? Also, if they modify a value inside $data should we persist the changes?

Show
Jonathan H. Wage added a comment - 28/Aug/10 11:25 AM Nice idea! So something like this could essentially work: /** @Document */ class User { /** @DynamicFields */ public $data; } $user = $dm->find(....); echo $user->data['username']; I am not sure if it is a good idea to just allow them to use a single @DynamicFields, maybe we should throw an exception if they use it that way? Also, if they modify a value inside $data should we persist the changes?
Hide
Permalink
Benjamin Eberlei added a comment - 28/Aug/10 12:34 PM

i guess the semantics should be, just one dynamic fields per entity allowed and that is inlined into the "normal" fields using array_merge() ?

Show
Benjamin Eberlei added a comment - 28/Aug/10 12:34 PM i guess the semantics should be, just one dynamic fields per entity allowed and that is inlined into the "normal" fields using array_merge() ?
Hide
Permalink
Benjamin Eberlei added a comment - 29/Aug/10 2:37 AM

ok maybe array_merge() is a bit dangerous, when the dynamic field has a property named like a real property.

But you could do $data = array_merge($dynamicData, $staticData); and should be fine then semantically, of course this should be documented

I think you should have at least an ID or not? but something like this would even be very fast for prototyping:

/** @Document */
class User
{
    /** @Id @Field */
    private $id;

    /** @DynamicFields */
    public $data;
}
Show
Benjamin Eberlei added a comment - 29/Aug/10 2:37 AM ok maybe array_merge() is a bit dangerous, when the dynamic field has a property named like a real property. But you could do $data = array_merge($dynamicData, $staticData); and should be fine then semantically, of course this should be documented I think you should have at least an ID or not? but something like this would even be very fast for prototyping: /** @Document */ class User { /** @Id @Field */ private $id; /** @DynamicFields */ public $data; }
Hide
Permalink
Jonathan H. Wage added a comment - 29/Aug/10 3:23 PM

After thinking about it and discussing it I think the @Collection type can do what is needed:

/** @Document */
class User
{
    /** @Id */
    private $id;

    /** @Collection */
    public $data = array();
}
Show
Jonathan H. Wage added a comment - 29/Aug/10 3:23 PM After thinking about it and discussing it I think the @Collection type can do what is needed: /** @Document */ class User { /** @Id */ private $id; /** @Collection */ public $data = array(); }

People

  • Assignee:
    Jonathan H. Wage
    Reporter:
    Benjamin Eberlei
Vote (0)
Watch (0)

Dates

  • Created:
    28/Aug/10 10:54 AM
    Updated:
    30/Aug/10 2:40 PM
    Resolved:
    30/Aug/10 2:40 PM
  • Atlassian JIRA (v5.2.7#850-sha1:b2af0c8)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Doctrine Project. Try JIRA - bug tracking software for your team.