Self response:

Just in case somebody wonders about it, i found that the problem is
that the object itself (discussion en my case) has the old id (0) and
by performing the save() i'm simply retrieving the id property of the
object, not the one from the db. Somehow the object needs to be
"updated". Theoretically it should be updated (page 150 on the book)
but it doesn't. Why ? no idea. btw, in the doSave () method (in the
propel generated model class) nowhere it seems to update this field.
Also, in this case it's an auto-generated field and it happens that
getting the last insert id is not an easy task. Although one could
easily go for

Propel::getConnection( )->getIdGenerator( )->getId()

strictly speaking this is a possible error for a high concurrency db
given the fact that although the lapsus between the insert and the
call to the last_insert_id () (which is what propel is doing) is
pretty small, we can't talk about precision here. If there are many
users trying to create new posts at the same time, one could insert
one after other user just added his but before he could get the
last_insert_id so that would be incorrect.

So what did i do ? given that there's no way to "natively" get the
correct id, the solution i found is a direct query (pure sql could be)
like

SELECT id FROM table WHERE <fktable.id> = <fkid> ORDER BY
creactionDate ASC LIMIT 1

(NOTE: this works only in my case because i have this field
creationDate timestamp)

Given that the variables come from some fields which had already been
inserted, they're verified. The only bad thing is that db portability
is lost but, well is either that or allowing a very very small, but
existing, chance of corrupted data.

Well, thinking twice, it could work too by destroying the object and
creating it again but that would require a query, and a lot of php
calls.

If someone has something to add, i'd appreciate.



On Oct 1, 5:43 pm, Julian Montreal <[EMAIL PROTECTED]> wrote:
> Hi, i'm a newbie into symfopny and i'm having this weird problem,
> could be something i'm doing wrong:
>
> I started with symfony 1.0 for learning it and then moving on to
> symfony 1.1. Also, due to this i'm using propel (the version which
> came with symfony).
>
> for learning, i'm trying to build a common forum-like application
> which allows persons to create discussions and post messages into
> them. I have a many to many relation which turned into this three
> tables:
>
> person (master)
> discussion (master)
> messages (detail for person and discussion)
>
> I'm trying to save a new discussion and a new message (person has
> already been created). So i make this:
>
> $discussion = new Discussion ();
> $discussion->setTitle ($this->getRequestParameter ('title'));
> $discussion->setPersonId ($this->getUser ()->getAttribute
> ('id'));        // from session
> $discussion->setcreationDate (time ());
> $discussion->save ();
>
> The problem i have is that after the save i can't get the correct id
> for discussion:
> $disc_id = $discussion->getId ();
>
> It ALWAYS returns 0. BUT in the database it's being saved with no
> problem (and btw, the id in the db is different as it's an integer not
> null auto_increment.
>
> table definition:
>
> create table discussion (
> id              integer primary key not null auto_increment,
>
> What could be wrong ? this should be an error on my side but i can't
> imagine which one because other tables and models i have behave
> without problems.
>
> i would reallya appreciate your help about this. After i learn propel
> "good" i would study doctrine and would decide if migrating or not.
>
> Julian.

--~--~---------~--~----~------------~-------~--~----~
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