22972 Posts in 11596 Topics by 2824 members
Page: 1 2
|Go to End||Next >|
17 June 2009 at 7:13am
How can I display and allow editing of $many_many_extraFields when using a control like the ManyManyComplexTableField?
When doing a many-to-many relationship, SilverStripe allows data to be stored in the junction table. This is set up using DataObject's static many_many_extraFields property.
The specific problem I'm trying to solve involves Quotes which may be related to any number of Qualities. Some of these relationships should be marked as primary. I've tried to do this using
public static $many_many_extraFields = array(
'Qualities' => array('Primary' => 'Boolean')
but would like the CMS admin user to have a way to edit this property.
20 June 2009 at 4:30am
I'm wondering if this is an uncommon thing to do in SS. I'm curious...how many of you out there have used $many_many_extraFields?
20 June 2009 at 1:21pm Last edited: 20 June 2009 1:29pm
AFAIK, there are currently no CRUD interfaces for many-to-many extra fields.
At the moment there's a way to add the extra data by setting the second parameter to the add() method when you're manipulating the relationship. Here's an example of adding a Member to a Group.
$member = new Member();
$group = DataObject::get_one('Group', "Code = 'forum-members'");
'Position' => 'Player'
There's also a way to inspect which extra fields are available for a relation using the method many_many_extraFields($component) (found on DataObject) where $component is the relationship name that you want the extra fields spec for.
Unfortunately, in the end you'll have to do your own code to add or edit extra fields columns on the junction table.
There is a plan to rework ComplexTableField so that it works in a more robust way, this would most likely include scaffolding the extra fields if you're editing a many-to-many relationship.
23 June 2009 at 12:15am
Thanks for this info, Sean.
17 December 2009 at 6:06pm
Is it still the case that there is no CRUD interface for many_many_extraFields?
20 January 2010 at 4:53pm Last edited: 20 January 2010 4:53pm
What Sean remarked allows to modify, add and remove rows from the join table, which was enough for me.
$cs = $group->getManyManyComponents('Member'); // returns ComponentSet
$cs->add($otherObj, array('FieldOnJoinTable'=>1)); // adds a row
$cs->add($otherObj, array('FieldOnJoinTable'=>2)); // modifies a row
When comes to querying though, this is a bit tricky, you need to use $join parameters of DataObject, or other getters. There are also other methods on ComponentSet like removeAll, setByIDList and so on, have a look at the ComponentSet. What else do you need?
25 March 2010 at 10:22pm
I would be interested in a CRUD interface for extra fields.
I want to define a many-many relation with three additional fields: one enumeration and two HTMLtext fields. Is there an easy way to enable these to be edited through the admin interface?
15 September 2010 at 6:06am
Yeah, this would be great. Any progress on this?
I actually want to use the data in the many_many_extraFields, not just filter my results based on it. This means that using a regular old $join on the DataObject won't work, since it doesn't actually join the tables. Had to resort to the old SQLQuery object. Am I missing something?
Page: 1 2
|Go to Top||Next >|