Great, this helps me get around around the Elixir way of thinking much
faster. Thanks a bunch.
I think a lot of my hesitation in this comes from worrying that Elixir
will start messing around with the table structure. I'm still a little
shaky as to what's going on under the hood, and when it will execute
certain commands. A lot of what I'm having to do is bridge several
tables at the same time, so I don't know how elixir would, say, commit
that data, if the class I've given it isn't a 1-to-1 matchup with the
table. Would it add any fields not in the table?
-J
On Tue, Jun 3, 2008 at 6:14 AM, Jason R. Coombs <[EMAIL PROTECTED]> wrote:
>
> If I understand your question, I think you can do this fairly easily.
>
> class File(Entity):
> id = Field(Integer, primary_key=True, colname='id_file')
> element = ManyToOne('Element') # need to define Element
> shots = OneToMany('Shot') # need to define Shot
> descriptor = Field(String(256))
> ...
> exports = OneToMany('Export', inverse='exported_file') # use this
> property to get all exports of a file
>
> class Export(Entity):
> source_file = ManyToOne('File')
> exported_file = ManyToOne('File')
> export_time = Field(DateTime)
>
> Then, to get the source files for a given file, do the following.
> some_file = Files.query.first()
> exports = some_file.exports
> sources = [export.source_file for export in exports]
>
>
> Obviously, I've made some assumptions about your model, but I hope
> this helps.
>
> Jason
>
> On Jun 2, 2:43 pm, Jason Porath <[EMAIL PROTECTED]> wrote:
>> Hey all.
>>
>> I'm in the process of porting over some SQL code to Elixir, to
>> determine how well it'd work as a backend for our pipe. We have some
>> fairly complicated queries, and I'm not sure how to model them. Here's
>> an example:
>>
>> SELECT files.id_file, files.id_element, files.descriptor,
>> files.id_file_type, files.id_staff AS id_staff_export,
>> exports.timestamp,
>> source_files.id_staff AS id_staff_files
>> FROM files
>> LEFT JOIN shots ON shots.id_shot=files.id_shot
>> LEFT JOIN exports ON exports.id_file_export=files.id_file
>> LEFT JOIN files AS source_files ON
>> exports.id_file_source=source_files.id_file
>> WHERE shots.id_shot=self.id_shot
>> AND files.version='hero'
>> ORDER BY files.id_element, descriptor, exports.timestamp DESC
>>
>> Basically, what is happening is that we have some files being
>> exported. In the process, a copy is made. Both original and source are
>> tracked in the database, as well as the actual act of exporting
>> (stored in "exports" table).
>>
>> I don't know how to join a table (in this case, "files") twice in
>> sqlAlchemy/Elixir. I don't have any leeway in changing the structure
>> of the data recording, unfortunately.
>>
>> Could anyone shed some light on this?
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"SQLElixir" 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/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---