I tried it with
$opinion = new Opinion();
$opfeat = new $opinion->OpinionFeature;
but cant find the class OpinionFeature...
Otherwise i do the same you write (more or less). I think that when i'm
showing opinion form it creates a new Opinion(); variable.
Then i use that variable to set the new OpinionFeature var...
$opfeat->setOpinionId($this->getObject()->id);
$opfeat->setFeatureId($feature->getId());
$OFform = new OpinionFeatureForm($opfeat);
$this->embedForm('feature_'.$feature->getId(), $OFform);
But it doesnt work... i have to overwrite saveEmbedForms....
public function saveEmbeddedForms($con = null, $forms = null)
{
foreach($this->getEmbeddedForms() as $opinionForm)
{
$opinionForm->getObject()->setOpinionId($this->getObject()->getId());
}
parent::saveEmbeddedForms($con, $forms);
}
I think there's a easier way to do this but.. i dont know. :(
2009/10/6 Dennis <[email protected]>
>
> I got this off of a Fabien post, somewhere. If you look at it, it
> makes everything connect to the same parent record. It SHOULD save
> correctly. I am goin to try it in my project tonight. Let me know if
> it works for you.
>
>
> $user = new User();
> $profile = new $user->Profile;
> $userForm = new UserForm($user);
> $profileForm = new ProfileForm($profile);
> $userForm->embedForm('Profile', $profileForm);
>
>
> On Oct 5, 2:13 am, elkrema <[email protected]> wrote:
> > Hi Dennis,
> >
> > there is my schema:
> >
> > Feature:
> > tableName: feature
> > columns:
> > id:
> > type: integer(8)
> > primary: true
> > autoincrement: true
> > name:
> > type: string(255)
> > notnull: true
> > created_at: timestamp(25)
> > updated_at: timestamp(25)
> > relations:
> > OpinionFeature:
> > local: id
> > foreign: feature_id
> > type: many
> >
> > Opinion:
> > tableName: opinion
> > columns:
> > id:
> > type: integer(8)
> > primary: true
> > autoincrement: true
> > title:
> > type: string(255)
> > notnull: true
> > opiniontxt:
> > type: string(2147483647)
> > notnull: true
> > is_active:
> > type: integer(1)
> > default: '0'
> > notnull: true
> > token:
> > type: string(255)
> > notnull: true
> > created_at: timestamp(25)
> > updated_at: timestamp(25)
> > relations:
> > OpinionFeature:
> > local: id
> > foreign: opinion_id
> > type: many
> >
> > OpinionFeature:
> > tableName: opinion_feature
> > columns:
> > opinion_id:
> > type: integer(8)
> > primary: true
> > feature_id:
> > type: integer(8)
> > primary: true
> > score:
> > type: float(2147483647)
> > notnull: true
> > created_at: timestamp(25)
> > updated_at: timestamp(25)
> > relations:
> > Opinion:
> > local: opinion_id
> > foreign: id
> > type: one
> > Feature:
> > local: feature_id
> > foreign: id
> > type: one
> >
> > Its very similar to your schema. Mine havent got foreign_type but i
> > think it works same yours... no?
> >
> > I did that with mysql workbench and then build schema... :)
> >
> > I think the problem was save embed forms i have to overwrite the
> > saveEmbedForms function to set the opinionid of the OpinionFeature
> > just at the moment of insert the opinion. Doing that it works, but i
> > dont know if its the right way.
> >
> > Thank you very much.
> >
> > On 5 oct, 05:10, Dennis <[email protected]> wrote:
> >
> > > So what you have is a:
> >
> > > <Opinion>--1-to-many --<OpinionFeature>--many-to-1--<Feature>
> >
> > > (above is a good way to show a schema)
> >
> > > So you have to set up your schema to reflect that:
> >
> > > Keep in mind that you have to create the Parents, before creating the
> > > children.
> > > Parents HAVE an ID, Children are GIVEN or USE and ID.
> >
> > > Parents are 'Opinion' and 'Feature'.
> >
> > > Opinion:
> > > tableName: opinion
> > > columns:
> > > opinion_id:
> > > type: integer(8)
> > > primary: true
> > > sequence: opinion_opinion_id
> > > opinion_name:
> > > type: string(65)
> > > notnull: true
> > > relations:
> > > OpinionFeature:
> > > local: opinion_id
> > > foreign: opinion_id
> > > type: many
> > > foreignType: one
> >
> > > Feature:
> > > tableName: feature
> > > columns:
> > > feature_id:
> > > type: integer(8)
> > > primary: true
> > > sequence: feature_feature_id
> > > feature_name:
> > > type: string(32)
> > > notnull: true
> > > feature_desc:
> > > type: string(128)
> > > notnull: true
> > > relations:
> > > OpinionFeature:
> > > local: feature_id
> > > foreign: feature_id
> > > type: many
> > > foreignType: one
> >
> > > OpinionFeature:
> > > tableName: opinionfeature
> > > columns:
> > > opinion_id:
> > > type: integer(8)
> > > primary: true
> > > feature_id:
> > > type: integer(8)
> > > primary: true
> > > score:
> > > type: integer(2)
> > > notnull: true
> > > relations:
> > > Opinion:
> > > local: opinion_id
> > > foreign: opinion_id
> > > type: one
> > > foreignType: many
> > > Feature:
> > > local: feature_id
> > > foreign: feature_id
> > > type: one
> > > foreignType: many
> >
> > > See if this works :-)
> >
> > > Personally, I like graphical database design tools. I make the design,
> > > have it spit out the code for the database that I'm using, then make
> > > the database, use Doctrine to build the schema (instead of composing
> > > it like above), make my model-forms-filters, and go.
> >
> > > I've had good luck using DezignForDatabases. The guy who makes it is
> > > very helpful and friendly. It's not perfect, but it's great for the
> > > price.
> > > On Oct 2, 3:39 am, Francisco José Núñez Rivera <[email protected]>
> > > wrote:
> >
> > > > But all the opinions have the same features.
> >
> > > > Feature -> id , desc
> > > > 1,Feature 1 ; 2, Feature2...
> >
> > > > Opinion shows all the features..
> > > > Feature 1 -Score:
> > > > Feature 2 - Score:
> >
> > > > OpinionFeature -> opinion_id , feature_id , score
> > > > I only insert a row here when im scoring a feature.
> >
> > > > I think my schema is right... no?
> >
> > > > Thank you very much.
> >
> > > > 2009/10/1 Abraham Montilla <[email protected]>
> >
> > > > > elkrema, if you have I have an Opinion with many Features then the
> right
> > > > > schema is
> >
> > > > > Feature is: id, opinion_id, desc
> > > > > OpinionFeature is: opinion_id, score
> >
> > > > > that's why you have an integrity constraint violation.... I don't
> know how
> > > > > i missed that first time i read your post hehe, that's all the
> problem
> >
> > > > > 2009/10/1 elkrema <[email protected]>
> >
> > > > >> With unsetting only option id doesn't work.
> >
> > > > >> The problem is that i am inserting the object of main form and the
> > > > >> embedded objects too.
> >
> > > > >> But i found a solution... I rewrite the function saveEmbeddedForms
> in
> > > > >> OpinionForm
> >
> > > > >> public function saveEmbeddedForms($con = null, $forms = null)
> > > > >> {
> >
> > > > >> foreach($this->getEmbeddedForms() as $opinionForm)
> > > > >> {
> >
> > > > >> $opinionForm->getObject()->setOpinionId($this->getObject()->getId
> > > > >> ());
> > > > >> }
> >
> > > > >> parent::saveEmbeddedForms($con, $forms);
> > > > >> }
> >
> > > > >> I set the opinionid before saving the embed forms....I dont know
> if is
> > > > >> the good way..
> >
> > > > >> Otherwise i have a new problem..
> >
> > > > >> when i'm editing an opinion the value of the last feature is not
> > > > >> showed.. ¿?
> >
> > > > >> Thank you!
> >
> > > > >> On 30 sep, 07:21, Abraham Montilla <[email protected]> wrote:
> > > > >> > try just unsetting opinion_id, tell me if works
> >
> > > > >> > 2009/9/29 elkrema <[email protected]>
> >
> > > > >> > > Hello Abraham,
> >
> > > > >> > > This is my code with i'm embedding forms in OpinionForm:
> >
> > > > >> > > foreach($this->getObject()->getFeatures() as $feature)
> > > > >> > > {
> > > > >> > > $opinionf = new OpinionFeature();
> > > > >> > > $opinionf->setOpinionId($this->getObject()->id);
> > > > >> > > $opinionf->setFeatureId($feature->getId());
> > > > >> > > $this->embedForm($feature->getName(), new OpinionFeatureForm
> > > > >> > > ($opinionf));
> > > > >> > > }
> >
> > > > >> > > With this code in when saving always get this flash message in
> the
> > > > >> > > first Feature...
> >
> > > > >> > > * Feature id: Invalid.
> >
> > > > >> > > And if i configure OpinionFeatureForm to unset the fields
> (just for
> > > > >> > > testing)
> >
> > > > >> > > unset($this['opinion_id'], $this['feature_id']);
> >
> > > > >> > > I get ..
> >
> > > > >> > > SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot
> add or
> > > > >> > > update a child row: a foreign key constraint fails
> > > > >> > > (`opinion`.`opinion_feature`, CONSTRAINT
> `opinion_feature_ibfk_1`
> > > > >> > > FOREIGN KEY (`opinion_id`) REFERENCES `opinion` (`id`) ON
> DELETE
> > > > >> > > CASCADE)
> >
> > > > >> > > Thank you for helping
> >
> > > > >> > > On 29 sep, 01:25, Abraham Montilla <[email protected]>
> wrote:
> > > > >> > > > i think it's because when embedding the OpinionFeatureForms
> you're
> > > > >> not
> > > > >> > > > setting properly the foreign key to the objects, would be
> something
> > > > >> like
> >
> > > > >> > > > for ( $i ..... ){
> > > > >> > > > $opfeat = new OpinionFeature();
> > > > >> > > > $opfeat->setOpinionId($this->getObject->getId());
> > > > >> > > > $OFform = new OpinionFeatureForm($opfeat);
> > > > >> > > > $this->embedForm('Feature_'.$i, $OFform);
> >
> > > > >> > > > }
> >
> > > > >> > > > 2009/9/28 elkrema <[email protected]>
> >
> > > > >> > > > > Hello
> >
> > > > >> > > > > i have some problems with my embed forms and i can't find
> a
> > > > >> > > > > solution...
> >
> > > > >> > > > > I have an Opinion with many Features..
> >
> > > > >> > > > > Feature is: id, desc
> > > > >> > > > > OpinionFeature is: opinion_id, feature_id,score
> >
> > > > >> > > > > In OpinionForm i'm inserting with [for each] all the
> features, but
> > > > >> > > > > when im creating a new opinion i always get [Integrity
> constraint
> > > > >> > > > > violation]
> >
> > > > >> > > > > I'ts easy get the id of the feature but i can get the ID
> of the
> > > > >> > > > > opinion because it isnt created yet... is null.
> >
> > > > >> > > > > Somebody can help me please? I get trought many forums and
> jobeet
> > > > >> > > > > tutorial but i cant get the solution!
> >
> > > > >> > > > > PS. Sorry for me english!!
> >
> > > > >> > > > --
> > > > >> > > > Have a nice day.
> > > > >> > > > Abraham Montilla.
> >
> > > > >> > --
> > > > >> > Have a nice day.
> > > > >> > Abraham Montilla.
> >
> > > > > --
> > > > > Have a nice day.
> > > > > Abraham Montilla.
> >
> >
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---